From f5e6290e433f99e93a5bb9e1580529450f261ebc Mon Sep 17 00:00:00 2001 From: Diego Ferreiro Val Date: Thu, 8 Mar 2018 00:32:48 -0800 Subject: [PATCH] fix: Disambiguate paths for build (#88) * Disambiguate paths * Fix tests --- .../best-build/src/__tests__/best-build.spec.js | 13 ++++++++++--- packages/best-build/src/index.js | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/best-build/src/__tests__/best-build.spec.js b/packages/best-build/src/__tests__/best-build.spec.js index 059e28e1..5fcb5d71 100644 --- a/packages/best-build/src/__tests__/best-build.spec.js +++ b/packages/best-build/src/__tests__/best-build.spec.js @@ -10,6 +10,7 @@ const MOCK_MESSAGER = { onBenchmarkBuildEnd() {}, logState() {} }; +const projectName = 'test'; function tempDir() { return fs.mkdtempSync(path.join(os.tmpdir(), TEMP_DIR_PREFIX)); @@ -22,14 +23,15 @@ describe('buildBenchmark', () => { path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'), { cacheDirectory, + projectName }, {}, MOCK_MESSAGER, ); - expect(fs.statSync(`${cacheDirectory}/single-file`).isDirectory()).toBe(true); - expect(fs.statSync(`${cacheDirectory}/single-file/single-file.html`).isFile()).toBe(true); - expect(fs.statSync(`${cacheDirectory}/single-file/single-file.js`).isFile()).toBe(true); + expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file`).isDirectory()).toBe(true); + expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file/single-file.html`).isFile()).toBe(true); + expect(fs.statSync(`${cacheDirectory}/${projectName}/single-file/single-file.js`).isFile()).toBe(true); }); test('build output', async () => { @@ -37,6 +39,7 @@ describe('buildBenchmark', () => { path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'), { cacheDirectory: tempDir(), + projectName }, {}, MOCK_MESSAGER, @@ -59,6 +62,8 @@ describe('buildBenchmark', () => { path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'), { cacheDirectory: tempDir(), + projectName + }, {}, messager, @@ -92,6 +97,7 @@ describe('buildBenchmark', () => { path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'), { cacheDirectory: tempDir(), + projectName, plugins: [['build-plugin-opts', PLUGIN_OPTIONS]], }, {}, @@ -127,6 +133,7 @@ describe('buildBenchmark', () => { path.resolve(__dirname, 'fixtures', 'single-file', 'single-file.js'), { cacheDirectory: tempDir(), + projectName, plugins: ['build-plugin-hooks'], }, {}, diff --git a/packages/best-build/src/index.js b/packages/best-build/src/index.js index c88444e2..dc611db6 100644 --- a/packages/best-build/src/index.js +++ b/packages/best-build/src/index.js @@ -34,11 +34,12 @@ function addResolverPlugins({ plugins }) { } export async function buildBenchmark(entry, projectConfig, globalConfig, messager) { - messager.onBenchmarkBuildStart(entry, projectConfig.projectName); + const { projectName, cacheDirectory } = projectConfig; + messager.onBenchmarkBuildStart(entry, projectName); const ext = path.extname(entry); const benchmarkName = path.basename(entry, ext); - const benchmarkFolder = path.join(projectConfig.cacheDirectory, benchmarkName); + const benchmarkFolder = path.join(cacheDirectory, projectName, benchmarkName); const benchmarkJSFileName = benchmarkName + ext; const inputOptions = Object.assign({}, BASE_ROLLUP_INPUT, { input: entry, @@ -67,7 +68,7 @@ export async function buildBenchmark(entry, projectConfig, globalConfig, message fs.writeFileSync(htmlPath, html, 'utf8'); - messager.onBenchmarkBuildEnd(entry, projectConfig.projectName); + messager.onBenchmarkBuildEnd(entry, projectName); return { benchmarkName,