diff --git a/apps/fabric-website/config/pre-copy.json b/apps/fabric-website/config/pre-copy.json index baf19c00de4c5b..f9c709ea4c3176 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 3fed74a80af96b..eedbd903c6e145 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('../../../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 { diff --git a/apps/fabric-website/src/pages/HomePage/HomePage.tsx b/apps/fabric-website/src/pages/HomePage/HomePage.tsx index b16d12b01cd386..29982fa7ca5021 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('../../../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 { 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 194928696fcbe1..2edd769d09811f 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('../../../../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 { public render(): JSX.Element { diff --git a/common/changes/@uifabric/fabric-website/redo_2018-05-30-04-52.json b/common/changes/@uifabric/fabric-website/redo_2018-05-30-04-52.json new file mode 100644 index 00000000000000..925b2bec6e943c --- /dev/null +++ b/common/changes/@uifabric/fabric-website/redo_2018-05-30-04-52.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "packageName": "@uifabric/fabric-website", + "comment": "made sure the deps are resolved by package rather than relative paths", + "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/redo_2018-05-30-04-52.json b/common/changes/office-ui-fabric-react/redo_2018-05-30-04-52.json new file mode 100644 index 00000000000000..500fce3f39a110 --- /dev/null +++ b/common/changes/office-ui-fabric-react/redo_2018-05-30-04-52.json @@ -0,0 +1,11 @@ +{ + "changes": [ + { + "comment": "", + "packageName": "office-ui-fabric-react", + "type": "none" + } + ], + "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 9b8e27e2eba3f0..bf01cca5ff31e0 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": [ - "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/**/*" ] } } \ No newline at end of file diff --git a/scripts/package.json b/scripts/package.json index 64adea8a112ff9..6868e8afaf32cf 100644 --- a/scripts/package.json +++ b/scripts/package.json @@ -32,6 +32,7 @@ "postcss-modules": "^0.8.0", "raf": "^3.4.0", "raw-loader": "^0.5.1", + "resolve": "^1.7.1", "sass-loader": "^6.0.6", "source-map-loader": "^0.2.1", "style-loader": "^0.19.0", diff --git a/scripts/require-resolve-cwd.js b/scripts/require-resolve-cwd.js new file mode 100644 index 00000000000000..308c91a5202d6e --- /dev/null +++ b/scripts/require-resolve-cwd.js @@ -0,0 +1,4 @@ +module.exports = function (request) { + const resolve = require('resolve'); + return resolve.sync(request, { basedir: process.cwd() }); +} \ No newline at end of file diff --git a/scripts/tasks/copy.js b/scripts/tasks/copy.js index f9e543d210d7c8..13b5eca99f4217 100644 --- a/scripts/tasks/copy.js +++ b/scripts/tasks/copy.js @@ -1,10 +1,41 @@ +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'); - configPath = path.resolve(process.cwd(), 'config/pre-copy.json'); + let configPath = path.resolve(process.cwd(), 'config/pre-copy.json'); if (!fs.existsSync(configPath)) { return; @@ -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); } diff --git a/scripts/tasks/jest-resources.js b/scripts/tasks/jest-resources.js index 6dbee44865c507..e873d289f8195b 100644 --- a/scripts/tasks/jest-resources.js +++ b/scripts/tasks/jest-resources.js @@ -1,5 +1,6 @@ const path = require('path'); const merge = require('./merge'); +const resolve = require('resolve'); const styleMockPath = module.exports = { @@ -12,13 +13,13 @@ const styleMockPath = createConfig: (customConfig) => merge( { moduleNameMapper: { - 'ts-jest': path.resolve(__dirname, '../node_modules/ts-jest'), + 'ts-jest': resolve.sync('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)': resolve.sync('ts-jest/preprocessor.js') }, 'reporters': [ diff --git a/scripts/tasks/jest.js b/scripts/tasks/jest.js index a234589a3ee908..7bf69d73dec235 100644 --- a/scripts/tasks/jest.js +++ b/scripts/tasks/jest.js @@ -3,11 +3,11 @@ module.exports = function (options) { const fs = require('fs'); const execSync = require('../exec-sync'); const findConfig = require('../find-config'); - const jestConfigPath = findConfig('jest.config.js'); + const resolve = require('resolve'); if (fs.existsSync(jestConfigPath)) { - const jestPath = path.resolve(__dirname, '../node_modules/jest/bin/jest'); + const jestPath = resolve.sync('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 0b70a00e71f97d..234800e7556ca4 100644 --- a/scripts/tasks/sass.js +++ b/scripts/tasks/sass.js @@ -1,6 +1,7 @@ module.exports = function (options) { const glob = require('glob'); const path = require('path'); + const requireResolveCwd = require('../require-resolve-cwd'); const _fileNameToClassMap = {}; @@ -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 = ''; diff --git a/scripts/tasks/ts.js b/scripts/tasks/ts.js index c1577af1391aa8..54fde896130a98 100644 --- a/scripts/tasks/ts.js +++ b/scripts/tasks/ts.js @@ -1,7 +1,8 @@ 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 resolve = require('resolve'); + const typescriptPath = 'node ' + resolve.sync('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 83ee5fce24e01e..f63cfddc045bae 100644 --- a/scripts/tasks/tslint.js +++ b/scripts/tasks/tslint.js @@ -2,11 +2,12 @@ module.exports = function (options) { const execSync = require('../exec-sync'); const path = require('path'); const fs = require('fs'); - const msCustomRulesMain = require.resolve('tslint-microsoft-contrib'); + const resolve = require('resolve'); + const msCustomRulesMain = resolve.sync('tslint-microsoft-contrib'); 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 ' + resolve.sync('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 359839801ded2b..e1f10b066c7b47 100644 --- a/scripts/tasks/webpack-resources.js +++ b/scripts/tasks/webpack-resources.js @@ -148,10 +148,6 @@ module.exports = { plugins: [ new WebpackNotifierPlugin(), - new webpack.WatchIgnorePlugin([ - /\.js$/, - /\.d\.ts$/ - ]), new ForkTsCheckerWebpackPlugin() ] },