From f6fa686c851dbe44d98a0181e93930f0de5c95a0 Mon Sep 17 00:00:00 2001 From: Ken Chau Date: Tue, 29 May 2018 16:21:40 -0700 Subject: [PATCH 1/3] Revert "Use require.resolve logic in builds & watch .js files from node_modules (#5007)" This reverts commit 779932c2e7d26eec3f77dae5e8f4e929c53e0551. --- apps/fabric-website/config/pre-copy.json | 2 +- .../src/pages/GetStarted/GetStartedPage.tsx | 2 +- .../src/pages/HomePage/HomePage.tsx | 4 +-- .../src/pages/Styles/IconsPage/IconsPage.tsx | 2 +- .../fixbuild_2018-05-26-05-50.json | 11 ------ .../fixbuild_2018-05-26-05-50.json | 11 ------ .../config/pre-copy.json | 14 ++++---- scripts/require-resolve-cwd.js | 3 -- scripts/tasks/copy.js | 35 ++----------------- scripts/tasks/jest-resources.js | 4 +-- scripts/tasks/jest.js | 2 +- scripts/tasks/sass.js | 14 +------- scripts/tasks/ts.js | 2 +- scripts/tasks/tslint.js | 2 +- scripts/tasks/webpack-resources.js | 4 +++ 15 files changed, 24 insertions(+), 88 deletions(-) delete mode 100644 common/changes/@uifabric/fabric-website/fixbuild_2018-05-26-05-50.json delete mode 100644 common/changes/office-ui-fabric-react/fixbuild_2018-05-26-05-50.json delete mode 100644 scripts/require-resolve-cwd.js diff --git a/apps/fabric-website/config/pre-copy.json b/apps/fabric-website/config/pre-copy.json index f9c709ea4c317..baf19c00de4c5 100644 --- a/apps/fabric-website/config/pre-copy.json +++ b/apps/fabric-website/config/pre-copy.json @@ -1,7 +1,7 @@ { "copyTo": { "lib": [ - "./src/**/*.json" + "src/**/*.json" ] } } \ No newline at end of file diff --git a/apps/fabric-website/src/pages/GetStarted/GetStartedPage.tsx b/apps/fabric-website/src/pages/GetStarted/GetStartedPage.tsx index eedbd903c6e14..3fed74a80af96 100644 --- a/apps/fabric-website/src/pages/GetStarted/GetStartedPage.tsx +++ b/apps/fabric-website/src/pages/GetStarted/GetStartedPage.tsx @@ -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('office-ui-fabric-core/package.json'); +const corePackageData = require('../../../node_modules/office-ui-fabric-core/package.json'); const corePackageVersion: string = corePackageData && corePackageData.version || '9.2.0'; export class GetStartedPage extends React.Component { diff --git a/apps/fabric-website/src/pages/HomePage/HomePage.tsx b/apps/fabric-website/src/pages/HomePage/HomePage.tsx index 29982fa7ca502..b16d12b01cd38 100644 --- a/apps/fabric-website/src/pages/HomePage/HomePage.tsx +++ b/apps/fabric-website/src/pages/HomePage/HomePage.tsx @@ -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('office-ui-fabric-core/package.json'); -const reactPackageData = require('office-ui-fabric-react/package.json'); +const corePackageData = require('../../../node_modules/office-ui-fabric-core/package.json'); +const reactPackageData = require('../../../node_modules/office-ui-fabric-react/package.json'); export class HomePage extends React.Component { public render(): JSX.Element { diff --git a/apps/fabric-website/src/pages/Styles/IconsPage/IconsPage.tsx b/apps/fabric-website/src/pages/Styles/IconsPage/IconsPage.tsx index 2edd769d09811..194928696fcbe 100644 --- a/apps/fabric-website/src/pages/Styles/IconsPage/IconsPage.tsx +++ b/apps/fabric-website/src/pages/Styles/IconsPage/IconsPage.tsx @@ -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('office-ui-fabric-core/src/data/icons.json'); +const iconData = require('../../../../node_modules/office-ui-fabric-core/src/data/icons.json'); export class IconsPage extends React.Component { public render(): JSX.Element { diff --git a/common/changes/@uifabric/fabric-website/fixbuild_2018-05-26-05-50.json b/common/changes/@uifabric/fabric-website/fixbuild_2018-05-26-05-50.json deleted file mode 100644 index 73b0d25bc15ba..0000000000000 --- a/common/changes/@uifabric/fabric-website/fixbuild_2018-05-26-05-50.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "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": "kchau@microsoft.com" -} \ No newline at end of file diff --git a/common/changes/office-ui-fabric-react/fixbuild_2018-05-26-05-50.json b/common/changes/office-ui-fabric-react/fixbuild_2018-05-26-05-50.json deleted file mode 100644 index f8d9a29fff1bb..0000000000000 --- a/common/changes/office-ui-fabric-react/fixbuild_2018-05-26-05-50.json +++ /dev/null @@ -1,11 +0,0 @@ -{ - "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": "kchau@microsoft.com" -} \ No newline at end of file diff --git a/packages/office-ui-fabric-react/config/pre-copy.json b/packages/office-ui-fabric-react/config/pre-copy.json index bf01cca5ff31e..9b8e27e2eba3f 100644 --- a/packages/office-ui-fabric-react/config/pre-copy.json +++ b/packages/office-ui-fabric-react/config/pre-copy.json @@ -1,17 +1,17 @@ { "copyTo": { "dist": [ - "./index.html" + "index.html" ], "dist/sass": [ - "office-ui-fabric-core/dist/sass/**/*", - "./src/common/_highContrast.scss", - "./src/common/_i18n.scss", - "./src/common/_semanticSlots.scss", - "./src/common/_themeOverrides.scss" + "node_modules/office-ui-fabric-core/dist/sass/**/*", + "src/common/_highContrast.scss", + "src/common/_i18n.scss", + "src/common/_semanticSlots.scss", + "src/common/_themeOverrides.scss" ], "dist/css": [ - "office-ui-fabric-core/dist/css/**/*" + "node_modules/office-ui-fabric-core/dist/css/**/*" ] } } \ No newline at end of file diff --git a/scripts/require-resolve-cwd.js b/scripts/require-resolve-cwd.js deleted file mode 100644 index 14ec330a3393b..0000000000000 --- a/scripts/require-resolve-cwd.js +++ /dev/null @@ -1,3 +0,0 @@ -module.exports = function (request) { - return require.resolve(request, { paths: [process.cwd()] }); -} \ No newline at end of file diff --git a/scripts/tasks/copy.js b/scripts/tasks/copy.js index 13b5eca99f421..f9e543d210d7c 100644 --- a/scripts/tasks/copy.js +++ b/scripts/tasks/copy.js @@ -1,41 +1,10 @@ -const path = require('path'); - -function expandSourcePath(pattern) { - const requireResolveCwd = require('../require-resolve-cwd'); - - if (!pattern) { - return null; - } - - // 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'); - let configPath = path.resolve(process.cwd(), 'config/pre-copy.json'); + configPath = path.resolve(process.cwd(), 'config/pre-copy.json'); if (!fs.existsSync(configPath)) { return; @@ -49,7 +18,7 @@ module.exports = function (options) { const sources = config.copyTo[destination]; for (let source of sources) { - source = expandSourcePath(source); + source = path.resolve(process.cwd(), source); destination = path.resolve(process.cwd(), destination); startCopy(source, destination); } diff --git a/scripts/tasks/jest-resources.js b/scripts/tasks/jest-resources.js index 30a1230ebd70c..6dbee44865c50 100644 --- a/scripts/tasks/jest-resources.js +++ b/scripts/tasks/jest-resources.js @@ -12,13 +12,13 @@ const styleMockPath = createConfig: (customConfig) => merge( { moduleNameMapper: { - 'ts-jest': require.resolve('ts-jest'), + 'ts-jest': path.resolve(__dirname, '../node_modules/ts-jest'), '\\.(scss)$': path.resolve(__dirname, 'jest-style-mock.js'), 'KeyCodes': path.resolve(__dirname, 'jest-mock.js') }, 'transform': { - '.(ts|tsx)': require.resolve('ts-jest/preprocessor.js') + '.(ts|tsx)': path.resolve(__dirname, '../node_modules/ts-jest/preprocessor.js') }, 'reporters': [ diff --git a/scripts/tasks/jest.js b/scripts/tasks/jest.js index 60b3be0771a4c..a234589a3ee90 100644 --- a/scripts/tasks/jest.js +++ b/scripts/tasks/jest.js @@ -7,7 +7,7 @@ module.exports = function (options) { const jestConfigPath = findConfig('jest.config.js'); if (fs.existsSync(jestConfigPath)) { - const jestPath = require.resolve('jest/bin/jest'); + const jestPath = path.resolve(__dirname, '../node_modules/jest/bin/jest'); const customArgs = options && options.argv ? options.argv.slice(3).join(' ') : ''; const args = [ diff --git a/scripts/tasks/sass.js b/scripts/tasks/sass.js index 234800e7556ca..0b70a00e71f97 100644 --- a/scripts/tasks/sass.js +++ b/scripts/tasks/sass.js @@ -1,7 +1,6 @@ module.exports = function (options) { const glob = require('glob'); const path = require('path'); - const requireResolveCwd = require('../require-resolve-cwd'); const _fileNameToClassMap = {}; @@ -87,22 +86,11 @@ 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 = requireResolvePackageUrl(url.substr(1)); + newUrl = path.resolve(process.cwd(), 'node_modules', url.substr(1)); } else if (url === 'stdin') { newUrl = ''; diff --git a/scripts/tasks/ts.js b/scripts/tasks/ts.js index 8f85a86a57508..4730eeb2e9489 100644 --- a/scripts/tasks/ts.js +++ b/scripts/tasks/ts.js @@ -1,7 +1,7 @@ module.exports = function (options) { const path = require('path'); const execSync = require('../exec-sync'); - const typescriptPath = 'node ' + require.resolve('typescript/lib/tsc'); + const typescriptPath = 'node ' + path.resolve(__dirname, '../node_modules/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)}` : ''); diff --git a/scripts/tasks/tslint.js b/scripts/tasks/tslint.js index 6d6d015b1140e..83ee5fce24e01 100644 --- a/scripts/tasks/tslint.js +++ b/scripts/tasks/tslint.js @@ -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 ' + require.resolve('tslint/lib/tslint-cli'); + const tslintPath = 'node ' + path.resolve(__dirname, '../node_modules/tslint/lib/tslint-cli'); execSync(`${tslintPath} --project ${projectPath} -t stylish -r ${rulesPath}`); }; diff --git a/scripts/tasks/webpack-resources.js b/scripts/tasks/webpack-resources.js index fc8cefb953015..c674366c1991e 100644 --- a/scripts/tasks/webpack-resources.js +++ b/scripts/tasks/webpack-resources.js @@ -148,6 +148,10 @@ module.exports = { plugins: [ new WebpackNotifierPlugin(), + new webpack.WatchIgnorePlugin([ + /\.js$/, + /\.d\.ts$/ + ]), new ForkTsCheckerWebpackPlugin() ] }, From 85ec51cac02e6d7b2b984fe0207191707f4b6890 Mon Sep 17 00:00:00 2001 From: Ken Chau Date: Tue, 29 May 2018 16:42:51 -0700 Subject: [PATCH 2/3] adding change files --- .../fabric-website/revert_2018-05-29-23-40.json | 11 +++++++++++ .../revert_2018-05-29-23-40.json | 11 +++++++++++ 2 files changed, 22 insertions(+) create mode 100644 common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json create mode 100644 common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json diff --git a/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json b/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json new file mode 100644 index 0000000000000..d0bd3f29f79e4 --- /dev/null +++ b/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@uifabric/fabric-website", + "comment": "revert build change\\", + "type": "patch" + } + ], + "packageName": "@uifabric/fabric-website", + "email": "kchau@microsoft.com" +} \ No newline at end of file diff --git a/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json b/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json new file mode 100644 index 0000000000000..72cf90a3f274e --- /dev/null +++ b/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "office-ui-fabric-react", + "comment": "revert build change", + "type": "patch" + } + ], + "packageName": "office-ui-fabric-react", + "email": "kchau@microsoft.com" +} \ No newline at end of file From fd4e20cd0952c21dc27d16db202cce4b1e42fb1a Mon Sep 17 00:00:00 2001 From: Ken Chau Date: Tue, 29 May 2018 16:46:36 -0700 Subject: [PATCH 3/3] fix the change file type to 'none' --- .../@uifabric/fabric-website/revert_2018-05-29-23-40.json | 4 ++-- .../office-ui-fabric-react/revert_2018-05-29-23-40.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json b/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json index d0bd3f29f79e4..a6163afca352d 100644 --- a/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json +++ b/common/changes/@uifabric/fabric-website/revert_2018-05-29-23-40.json @@ -2,8 +2,8 @@ "changes": [ { "packageName": "@uifabric/fabric-website", - "comment": "revert build change\\", - "type": "patch" + "comment": "revert build change", + "type": "none" } ], "packageName": "@uifabric/fabric-website", diff --git a/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json b/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json index 72cf90a3f274e..7502f047678f6 100644 --- a/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json +++ b/common/changes/office-ui-fabric-react/revert_2018-05-29-23-40.json @@ -3,7 +3,7 @@ { "packageName": "office-ui-fabric-react", "comment": "revert build change", - "type": "patch" + "type": "none" } ], "packageName": "office-ui-fabric-react",