From 64986611ef37675f2f65d776d8737e97e77fd0f3 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Sat, 28 Jul 2018 13:23:15 +0200 Subject: [PATCH 1/4] Add test cases: basic, basic with cwd, custom, custom with cwd (:warn: snapshot for custom with cwd doesn't contain dist) --- package.json | 2 +- test/__snapshots__/index.test.js.snap | 69 +++++++++++++++++++ .../basic-with-cwd/basic/package.json | 3 + .../basic-with-cwd/basic/src/index.js | 5 ++ test/fixtures/basic-with-cwd/basic/src/two.js | 3 + test/fixtures/basic-with-cwd/package.json | 6 ++ .../custom-source/package.json | 4 ++ .../custom-source/src/custom-source.js | 5 ++ .../custom-source/src/two.js | 3 + .../custom-source-with-cwd/package.json | 6 ++ test/fixtures/custom-source/package.json | 4 ++ .../custom-source/src/custom-source.js | 5 ++ test/fixtures/custom-source/src/two.js | 3 + 13 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 test/fixtures/basic-with-cwd/basic/package.json create mode 100644 test/fixtures/basic-with-cwd/basic/src/index.js create mode 100644 test/fixtures/basic-with-cwd/basic/src/two.js create mode 100644 test/fixtures/basic-with-cwd/package.json create mode 100644 test/fixtures/custom-source-with-cwd/custom-source/package.json create mode 100644 test/fixtures/custom-source-with-cwd/custom-source/src/custom-source.js create mode 100644 test/fixtures/custom-source-with-cwd/custom-source/src/two.js create mode 100644 test/fixtures/custom-source-with-cwd/package.json create mode 100644 test/fixtures/custom-source/package.json create mode 100644 test/fixtures/custom-source/src/custom-source.js create mode 100644 test/fixtures/custom-source/src/two.js diff --git a/package.json b/package.json index d011116..1a9faee 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prepare": "npm run -s build", "prepare:babel": "babel --presets env src/*.js -d dist && npm t", "lint": "eslint src", - "test": "npm run -s lint && npm run -s build && jest", + "test": "npm run -s lint && npm run -s build && jest --env=node", "release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" }, "repository": "developit/microbundle", diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index 3e93682..af2a9fe 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -105,6 +105,75 @@ 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 + package.json + src + custom-source.js + two.js + package.json + + +Build \\"customSrc\\" to dist:" +`; + 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); +} From 56f6b7a6973f7cd8b0751047ba35f9535239e40e Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Sat, 28 Jul 2018 13:44:52 +0200 Subject: [PATCH 2/4] Fix custom source with cwd issue: resolve source path before passing it further --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, From 6aa17a08177f8bd18d65f2ca4811ae9c4f5a0b24 Mon Sep 17 00:00:00 2001 From: Sergey Petushkov Date: Sat, 28 Jul 2018 13:45:38 +0200 Subject: [PATCH 3/4] Update snapshot for the fixed issue --- test/__snapshots__/index.test.js.snap | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/test/__snapshots__/index.test.js.snap b/test/__snapshots__/index.test.js.snap index af2a9fe..e1c6140 100644 --- a/test/__snapshots__/index.test.js.snap +++ b/test/__snapshots__/index.test.js.snap @@ -164,6 +164,13 @@ 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 @@ -171,7 +178,10 @@ custom-source-with-cwd package.json -Build \\"customSrc\\" to dist:" +Build \\"customSrc\\" to dist: +211 B: custom-src.js +211 B: custom-src.mjs +291 B: custom-src.umd.js" `; exports[`fixtures jsx 1`] = ` From 005651de48515b29cbe8f77b965b15794656e026 Mon Sep 17 00:00:00 2001 From: Sergey Date: Sun, 29 Jul 2018 10:59:40 +0200 Subject: [PATCH 4/4] Revert jest env change Moved to separate PR: https://github.com/developit/microbundle/pull/179 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 1a9faee..d011116 100644 --- a/package.json +++ b/package.json @@ -13,7 +13,7 @@ "prepare": "npm run -s build", "prepare:babel": "babel --presets env src/*.js -d dist && npm t", "lint": "eslint src", - "test": "npm run -s lint && npm run -s build && jest --env=node", + "test": "npm run -s lint && npm run -s build && jest", "release": "npm run -s prepare && npm test && git commit -am $npm_package_version && git tag $npm_package_version && git push && git push --tags && npm publish" }, "repository": "developit/microbundle",