diff --git a/src/index.js b/src/index.js index 081e9f9..944d790 100644 --- a/src/index.js +++ b/src/index.js @@ -94,7 +94,7 @@ export default async function microbundle(options) { .concat( options.entries && options.entries.length ? options.entries - : options.pkg.source || + : (options.pkg.source && resolve(cwd, options.pkg.source)) || ((await isDir(resolve(cwd, 'src'))) && (await jsOrTs('src/index'))) || (await jsOrTs('index')) || options.pkg.module, diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 3e93682..e1c6140 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -105,6 +105,85 @@ Build \\"basicLibTsx\\" to dist: 295 B: basic-lib-tsx.umd.js" `; +exports[`fixtures basic-with-cwd 1`] = ` +"Used script: microbundle --cwd ./basic + +Directory tree: + +basic-with-cwd + basic + dist + basic.js + basic.js.map + basic.mjs + basic.mjs.map + basic.umd.js + basic.umd.js.map + package.json + src + index.js + two.js + package.json + + +Build \\"basic\\" to dist: +211 B: basic.js +211 B: basic.mjs +287 B: basic.umd.js" +`; + +exports[`fixtures custom-source 1`] = ` +"Used script: microbundle + +Directory tree: + +custom-source + dist + custom-source.js + custom-source.js.map + custom-source.mjs + custom-source.mjs.map + custom-source.umd.js + custom-source.umd.js.map + package.json + src + custom-source.js + two.js + + +Build \\"customSource\\" to dist: +211 B: custom-source.js +211 B: custom-source.mjs +293 B: custom-source.umd.js" +`; + +exports[`fixtures custom-source-with-cwd 1`] = ` +"Used script: microbundle --cwd ./custom-source + +Directory tree: + +custom-source-with-cwd + custom-source + dist + custom-src.js + custom-src.js.map + custom-src.mjs + custom-src.mjs.map + custom-src.umd.js + custom-src.umd.js.map + package.json + src + custom-source.js + two.js + package.json + + +Build \\"customSrc\\" to dist: +211 B: custom-src.js +211 B: custom-src.mjs +291 B: custom-src.umd.js" +`; + exports[`fixtures jsx 1`] = ` "Used script: microbundle diff --git a/test/fixtures/basic-with-cwd/basic/package.json b/test/fixtures/basic-with-cwd/basic/package.json new file mode 100644 index 0000000..d1949ef --- /dev/null +++ b/test/fixtures/basic-with-cwd/basic/package.json @@ -0,0 +1,3 @@ +{ + "name": "basic" +} diff --git a/test/fixtures/basic-with-cwd/basic/src/index.js b/test/fixtures/basic-with-cwd/basic/src/index.js new file mode 100644 index 0000000..a756a0a --- /dev/null +++ b/test/fixtures/basic-with-cwd/basic/src/index.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/basic-with-cwd/basic/src/two.js b/test/fixtures/basic-with-cwd/basic/src/two.js new file mode 100644 index 0000000..9f1f741 --- /dev/null +++ b/test/fixtures/basic-with-cwd/basic/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/basic-with-cwd/package.json b/test/fixtures/basic-with-cwd/package.json new file mode 100644 index 0000000..c0f4418 --- /dev/null +++ b/test/fixtures/basic-with-cwd/package.json @@ -0,0 +1,6 @@ +{ + "name": "basic-with-cwd", + "scripts": { + "build": "microbundle --cwd ./basic" + } +} diff --git a/test/fixtures/custom-source-with-cwd/custom-source/package.json b/test/fixtures/custom-source-with-cwd/custom-source/package.json new file mode 100644 index 0000000..d966cf2 --- /dev/null +++ b/test/fixtures/custom-source-with-cwd/custom-source/package.json @@ -0,0 +1,4 @@ +{ + "name": "custom-src", + "source": "src/custom-source.js" +} diff --git a/test/fixtures/custom-source-with-cwd/custom-source/src/custom-source.js b/test/fixtures/custom-source-with-cwd/custom-source/src/custom-source.js new file mode 100644 index 0000000..a756a0a --- /dev/null +++ b/test/fixtures/custom-source-with-cwd/custom-source/src/custom-source.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/custom-source-with-cwd/custom-source/src/two.js b/test/fixtures/custom-source-with-cwd/custom-source/src/two.js new file mode 100644 index 0000000..9f1f741 --- /dev/null +++ b/test/fixtures/custom-source-with-cwd/custom-source/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/custom-source-with-cwd/package.json b/test/fixtures/custom-source-with-cwd/package.json new file mode 100644 index 0000000..7ec564d --- /dev/null +++ b/test/fixtures/custom-source-with-cwd/package.json @@ -0,0 +1,6 @@ +{ + "name": "custom-source-with-cwd", + "scripts": { + "build": "microbundle --cwd ./custom-source" + } +} diff --git a/test/fixtures/custom-source/package.json b/test/fixtures/custom-source/package.json new file mode 100644 index 0000000..b83de40 --- /dev/null +++ b/test/fixtures/custom-source/package.json @@ -0,0 +1,4 @@ +{ + "name": "custom-source", + "source": "src/custom-source.js" +} diff --git a/test/fixtures/custom-source/src/custom-source.js b/test/fixtures/custom-source/src/custom-source.js new file mode 100644 index 0000000..a756a0a --- /dev/null +++ b/test/fixtures/custom-source/src/custom-source.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/custom-source/src/two.js b/test/fixtures/custom-source/src/two.js new file mode 100644 index 0000000..9f1f741 --- /dev/null +++ b/test/fixtures/custom-source/src/two.js @@ -0,0 +1,3 @@ +export async function two(...args) { + return args.reduce((total, value) => total + value, 0); +}