diff --git a/src/index.js b/src/index.js index c1e2f151..9c7f5fa1 100644 --- a/src/index.js +++ b/src/index.js @@ -218,7 +218,7 @@ async function getInput({ entries, cwd, source, module }) { (await jsOrTs(cwd, 'index')) || module, ) - .map(file => glob(file)) + .map(file => glob(file, { cwd })) .forEach(file => input.push(...file)); return input; diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 27dedc37..fadc962b 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -1280,6 +1280,54 @@ exports[`fixtures build class-properties with microbundle 5`] = ` " `; +exports[`fixtures build cli-entry-with-cwd with microbundle 1`] = ` +"Used script: microbundle + +Directory tree: + +cli-entry + dist + cli-entry.esm.mjs + cli-entry.esm.mjs.map + cli-entry.js + cli-entry.js.map + cli-entry.umd.js + cli-entry.umd.js.map + package.json + src + one.js + two.js + + +Build \\"cli-entry\\" to dist: +187 B: cli-entry.js.gz +138 B: cli-entry.js.br +188 B: cli-entry.esm.mjs.gz +139 B: cli-entry.esm.mjs.br +272 B: cli-entry.umd.js.gz +202 B: cli-entry.umd.js.br" +`; + +exports[`fixtures build cli-entry-with-cwd with microbundle 2`] = `6`; + +exports[`fixtures build cli-entry-with-cwd with microbundle 3`] = ` +"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};export default function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}} +//# sourceMappingURL=cli-entry.esm.mjs.map +" +`; + +exports[`fixtures build cli-entry-with-cwd with microbundle 4`] = ` +"var r=function(){try{var r=arguments;return Promise.resolve([].slice.call(r).reduce(function(r,e){return r+e},0))}catch(r){return Promise.reject(r)}};module.exports=function(){try{var e=arguments,t=[].slice.call(e);return Promise.resolve(r.apply(void 0,t)).then(function(e){return Promise.resolve(r.apply(void 0,t)).then(function(r){return[e,r]})})}catch(r){return Promise.reject(r)}}; +//# sourceMappingURL=cli-entry.js.map +" +`; + +exports[`fixtures build cli-entry-with-cwd with microbundle 5`] = ` +"!function(e,r){\\"object\\"==typeof exports&&\\"undefined\\"!=typeof module?module.exports=r():\\"function\\"==typeof define&&define.amd?define(r):(e||self).cliEntry=r()}(this,function(){var e=function(){try{var e=arguments;return Promise.resolve([].slice.call(e).reduce(function(e,r){return e+r},0))}catch(e){return Promise.reject(e)}};return function(){try{var r=arguments,n=[].slice.call(r);return Promise.resolve(e.apply(void 0,n)).then(function(r){return Promise.resolve(e.apply(void 0,n)).then(function(e){return[r,e]})})}catch(e){return Promise.reject(e)}}}); +//# sourceMappingURL=cli-entry.umd.js.map +" +`; + exports[`fixtures build css-modules--false with microbundle 1`] = ` "Used script: microbundle --no-sourcemap --css-modules false diff --git a/test/fixtures/cli-entry-with-cwd/cli-entry/package.json b/test/fixtures/cli-entry-with-cwd/cli-entry/package.json new file mode 100644 index 00000000..1a246559 --- /dev/null +++ b/test/fixtures/cli-entry-with-cwd/cli-entry/package.json @@ -0,0 +1,3 @@ +{ + "name": "cli-entry" +} diff --git a/test/fixtures/cli-entry-with-cwd/cli-entry/src/one.js b/test/fixtures/cli-entry-with-cwd/cli-entry/src/one.js new file mode 100644 index 00000000..c0a2efb0 --- /dev/null +++ b/test/fixtures/cli-entry-with-cwd/cli-entry/src/one.js @@ -0,0 +1,5 @@ +import { two } from './two'; + +export default async function (...args) { + return [await two(...args), await two(...args)]; +} diff --git a/test/fixtures/cli-entry-with-cwd/cli-entry/src/two.js b/test/fixtures/cli-entry-with-cwd/cli-entry/src/two.js new file mode 100644 index 00000000..9f1f741b --- /dev/null +++ b/test/fixtures/cli-entry-with-cwd/cli-entry/src/two.js @@ -0,0 +1,3 @@ +export async function two(...args) { + return args.reduce((total, value) => total + value, 0); +} diff --git a/test/fixtures/cli-entry-with-cwd/package.json b/test/fixtures/cli-entry-with-cwd/package.json new file mode 100644 index 00000000..43901e3a --- /dev/null +++ b/test/fixtures/cli-entry-with-cwd/package.json @@ -0,0 +1,6 @@ +{ + "name": "cli-entry-with-cwd", + "scripts": { + "build": "microbundle src/one.js --cwd ./cli-entry" + } +} diff --git a/tools/build-fixture.js b/tools/build-fixture.js index 653b63fa..82c35188 100644 --- a/tools/build-fixture.js +++ b/tools/build-fixture.js @@ -56,6 +56,10 @@ export const buildDirectory = async fixtureDir => { await rimraf(resolve(`${fixturePath}/.rts2_cache_es`)); await rimraf(resolve(`${fixturePath}/.rts2_cache_umd`)); + // Now that dirs have been cleared, reset the fixturePath back to the parent dir + if (fixtureDir.endsWith('-with-cwd')) { + fixturePath = resolve(FIXTURES_DIR, fixtureDir); + } const script = await getBuildScript(fixturePath, DEFAULT_SCRIPT); const prevDir = process.cwd();