diff --git a/packages/core/integration-tests/test/babel.js b/packages/core/integration-tests/test/babel.js index cbd333f9cf3..5d49c04f334 100644 --- a/packages/core/integration-tests/test/babel.js +++ b/packages/core/integration-tests/test/babel.js @@ -1,5 +1,6 @@ // @flow import assert from 'assert'; +import invariant from 'assert'; import path from 'path'; import { bundle, @@ -415,6 +416,35 @@ describe('babel', function () { assert(distFile.includes('something different')); }); + it('should rebuild when declared external dependencies change', async function () { + let inputDir = tempy.directory(); + let filepath = path.join(inputDir, 'file.txt'); + + await fs.ncp( + path.join(__dirname, 'integration/babel-external-deps'), + inputDir, + ); + + let b = bundler(path.join(inputDir, 'index.js'), { + outputFS: fs, + shouldAutoInstall: true, + }); + + subscription = await b.watch(); + let build = await getNextBuild(b); + invariant(build.type === 'buildSuccess'); + let distFile = await fs.readFile(path.join(distDir, 'index.js'), 'utf8'); + assert(distFile.includes('foo')); + assert(!distFile.includes('bar')); + + await fs.writeFile(filepath, 'bar'); + build = await getNextBuild(b); + invariant(build.type === 'buildSuccess'); + distFile = await fs.readFile(path.join(distDir, 'index.js'), 'utf8'); + assert(distFile.includes('bar')); + assert(!distFile.includes('foo')); + }); + it('should invalidate babel.config.js across runs', async function () { let dateRe = /return (\d+);/; diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/.babelrc b/packages/core/integration-tests/test/integration/babel-external-deps/.babelrc new file mode 100644 index 00000000000..ce4a6735b9c --- /dev/null +++ b/packages/core/integration-tests/test/integration/babel-external-deps/.babelrc @@ -0,0 +1,3 @@ +{ + "plugins": [["./plugin.js", { "filename": "file.txt" }]] +} diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/file.txt b/packages/core/integration-tests/test/integration/babel-external-deps/file.txt new file mode 100644 index 00000000000..257cc5642cb --- /dev/null +++ b/packages/core/integration-tests/test/integration/babel-external-deps/file.txt @@ -0,0 +1 @@ +foo diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/index.js b/packages/core/integration-tests/test/integration/babel-external-deps/index.js new file mode 100644 index 00000000000..97ecfbae3a7 --- /dev/null +++ b/packages/core/integration-tests/test/integration/babel-external-deps/index.js @@ -0,0 +1 @@ +console.log(REPLACE_ME); diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/package.json b/packages/core/integration-tests/test/integration/babel-external-deps/package.json new file mode 100644 index 00000000000..dd236006194 --- /dev/null +++ b/packages/core/integration-tests/test/integration/babel-external-deps/package.json @@ -0,0 +1,4 @@ +{ + "name": "babel-external-deps", + "version": "1.0.0" +} diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/plugin.js b/packages/core/integration-tests/test/integration/babel-external-deps/plugin.js new file mode 100644 index 00000000000..814d985a55f --- /dev/null +++ b/packages/core/integration-tests/test/integration/babel-external-deps/plugin.js @@ -0,0 +1,21 @@ +const fs = require("fs"); +const path = require("path"); + +module.exports = function (api, { filename }) { + const { types: t } = api; + + const filepath = path.join(__dirname, filename); + const contents = fs.readFileSync(filepath, "utf8"); + api.cache.never(); + api.addExternalDependency(filepath); + + return { + visitor: { + Identifier(path) { + if (path.node.name === "REPLACE_ME") { + path.replaceWith(t.stringLiteral(contents)); + } + }, + }, + }; +}; diff --git a/packages/core/integration-tests/test/integration/babel-external-deps/yarn.lock b/packages/core/integration-tests/test/integration/babel-external-deps/yarn.lock new file mode 100644 index 00000000000..e69de29bb2d