Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apps/fabric-website/config/pre-copy.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"copyTo": {
"lib": [
"src/**/*.json"
"./src/**/*.json"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const diagramStyles: any = require('./GetStartedPage.diagram.module.scss');
import * as stylesImport from './GetStartedPage.module.scss';
const styles: any = stylesImport;
const pageStyles: any = require('../PageStyles.module.scss');
const corePackageData = require('../../../node_modules/office-ui-fabric-core/package.json');
const corePackageData = require('office-ui-fabric-core/package.json');
const corePackageVersion: string = corePackageData && corePackageData.version || '9.2.0';

export class GetStartedPage extends React.Component<any, any> {
Expand Down
4 changes: 2 additions & 2 deletions apps/fabric-website/src/pages/HomePage/HomePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { css } from 'office-ui-fabric-react/lib/Utilities';
import * as stylesImport from './HomePage.module.scss';
const styles: any = stylesImport;

const corePackageData = require('../../../node_modules/office-ui-fabric-core/package.json');
const reactPackageData = require('../../../node_modules/office-ui-fabric-react/package.json');
const corePackageData = require('office-ui-fabric-core/package.json');
const reactPackageData = require('office-ui-fabric-react/package.json');

export class HomePage extends React.Component<any, any> {
public render(): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import * as stylesImport from './IconsPage.module.scss';
const styles: any = stylesImport;
const pageStyles: any = require('../../PageStyles.module.scss');

const iconData = require('../../../../node_modules/office-ui-fabric-core/src/data/icons.json');
const iconData = require('office-ui-fabric-core/src/data/icons.json');

export class IconsPage extends React.Component<any, any> {
public render(): JSX.Element {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "@uifabric/fabric-website",
"comment": "Use require.resolve logic in builds & watch .js files from node_modules",
"type": "patch"
}
],
"packageName": "@uifabric/fabric-website",
"email": "[email protected]"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"packageName": "office-ui-fabric-react",
"comment": "Use require.resolve logic in builds & watch .js files from node_modules",
"type": "patch"
}
],
"packageName": "office-ui-fabric-react",
"email": "[email protected]"
}
14 changes: 7 additions & 7 deletions packages/office-ui-fabric-react/config/pre-copy.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"copyTo": {
"dist": [
"index.html"
"./index.html"
],
"dist/sass": [
"node_modules/office-ui-fabric-core/dist/sass/**/*",
"src/common/_highContrast.scss",
"src/common/_i18n.scss",
"src/common/_semanticSlots.scss",
"src/common/_themeOverrides.scss"
"office-ui-fabric-core/dist/sass/**/*",
"./src/common/_highContrast.scss",
"./src/common/_i18n.scss",
"./src/common/_semanticSlots.scss",
"./src/common/_themeOverrides.scss"
],
"dist/css": [
"node_modules/office-ui-fabric-core/dist/css/**/*"
"office-ui-fabric-core/dist/css/**/*"
]
}
}
3 changes: 3 additions & 0 deletions scripts/require-resolve-cwd.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = function (request) {
return require.resolve(request, { paths: [process.cwd()] });
}
35 changes: 33 additions & 2 deletions scripts/tasks/copy.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
const path = require('path');

function expandSourcePath(pattern) {
const requireResolveCwd = require('../require-resolve-cwd');

if (!pattern) {
return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would a build error be useful here or does this result in an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It'll throw something like this:

TypeError: glob pattern string required

Now, I don't think we can ever get into this situation really because pattern is passed in from a key of a json object. I suppose I'm trying to be too cautious here.

}

// just returns the relative paths
if (pattern.startsWith('.')) {
return pattern;
}

// tries to resolve the packages, handling scoped packages
const splitPattern = pattern.split('/');
const packageName = pattern[0] == '@' ? `${splitPattern[0]}/${splitPattern[1]}` : splitPattern[0];

try {
const resolvedPackageJson = requireResolveCwd(`${packageName}/package.json`);

if (!resolvedPackageJson) {
// returns pattern if the packageName didn't contain a package.json (not really a package)
return pattern;
}

return pattern.replace(packageName, path.dirname(resolvedPackageJson));
} catch (e) {
console.error(e);
}
}

module.exports = function (options) {
const { logStartTask, logEndTask } = require('../logging');
const path = require('path');
const fs = require('fs');

configPath = path.resolve(process.cwd(), 'config/pre-copy.json');
let configPath = path.resolve(process.cwd(), 'config/pre-copy.json');

if (!fs.existsSync(configPath)) {
return;
Expand All @@ -18,7 +49,7 @@ module.exports = function (options) {
const sources = config.copyTo[destination];

for (let source of sources) {
source = path.resolve(process.cwd(), source);
source = expandSourcePath(source);
destination = path.resolve(process.cwd(), destination);
startCopy(source, destination);
}
Expand Down
4 changes: 2 additions & 2 deletions scripts/tasks/jest-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ const styleMockPath =
createConfig: (customConfig) => merge(
{
moduleNameMapper: {
'ts-jest': path.resolve(__dirname, '../node_modules/ts-jest'),
'ts-jest': require.resolve('ts-jest'),
'\\.(scss)$': path.resolve(__dirname, 'jest-style-mock.js'),
'KeyCodes': path.resolve(__dirname, 'jest-mock.js')
},

'transform': {
'.(ts|tsx)': path.resolve(__dirname, '../node_modules/ts-jest/preprocessor.js')
'.(ts|tsx)': require.resolve('ts-jest/preprocessor.js')
},

'reporters': [
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/jest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = function (options) {
const jestConfigPath = findConfig('jest.config.js');

if (fs.existsSync(jestConfigPath)) {
const jestPath = path.resolve(__dirname, '../node_modules/jest/bin/jest');
const jestPath = require.resolve('jest/bin/jest');
const customArgs = options && options.argv ? options.argv.slice(3).join(' ') : '';

const args = [
Expand Down
14 changes: 13 additions & 1 deletion scripts/tasks/sass.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module.exports = function (options) {
const glob = require('glob');
const path = require('path');
const requireResolveCwd = require('../require-resolve-cwd');

const _fileNameToClassMap = {};

Expand Down Expand Up @@ -86,11 +87,22 @@ module.exports = function (options) {
return source.join('\n');
}

function requireResolvePackageUrl(packageUrl) {
const fullName = packageUrl + (packageUrl.endsWith('.scss') ? '' : '.scss');

try {
return requireResolveCwd(fullName);
} catch (e) {
// try again with a private reference
return requireResolveCwd(path.join(path.dirname(fullName), `_${path.basename(fullName)}`));
}
}

function patchSassUrl(url, prev, done) {
let newUrl = url;

if (url[0] === '~') {
newUrl = path.resolve(process.cwd(), 'node_modules', url.substr(1));
newUrl = requireResolvePackageUrl(url.substr(1));
}
else if (url === 'stdin') {
newUrl = '';
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/ts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
module.exports = function (options) {
const path = require('path');
const execSync = require('../exec-sync');
const typescriptPath = 'node ' + path.resolve(__dirname, '../node_modules/typescript/lib/tsc');
const typescriptPath = 'node ' + require.resolve('typescript/lib/tsc');
const libPath = path.resolve(process.cwd(), 'lib');
const srcPath = path.resolve(process.cwd(), 'src');
const extraParams = '--pretty' + (options.isProduction ? ` --inlineSources --sourceRoot ${path.relative(libPath, srcPath)}` : '');
Expand Down
2 changes: 1 addition & 1 deletion scripts/tasks/tslint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = function (options) {
const rulesPath = path.dirname(msCustomRulesMain);
const projectPath = path.resolve(process.cwd(), 'tsconfig.json');
const sourcePath = path.resolve(process.cwd(), 'src/**/*.ts*');
const tslintPath = 'node ' + path.resolve(__dirname, '../node_modules/tslint/lib/tslint-cli');
const tslintPath = 'node ' + require.resolve('tslint/lib/tslint-cli');

execSync(`${tslintPath} --project ${projectPath} -t stylish -r ${rulesPath}`);
};
4 changes: 0 additions & 4 deletions scripts/tasks/webpack-resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,6 @@ module.exports = {

plugins: [
new WebpackNotifierPlugin(),
new webpack.WatchIgnorePlugin([
/\.js$/,
/\.d\.ts$/
]),
new ForkTsCheckerWebpackPlugin()
]
},
Expand Down