Skip to content

Commit 1007d3e

Browse files
committed
Address feedback, and adds more tests
1 parent c7980ae commit 1007d3e

File tree

14 files changed

+109
-68
lines changed

14 files changed

+109
-68
lines changed

.github/workflows/CI.yml

+58-35
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,64 @@
11
name: CI
2-
on: pull_request
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
- release-*
8+
pull_request:
9+
branches:
10+
- master
11+
- release-*
312

413
jobs:
5-
test:
14+
ci:
615
runs-on: ubuntu-latest
716

17+
strategy:
18+
matrix:
19+
node-version: [10.x, 12.x, 14.x]
20+
821
steps:
9-
- uses: actions/checkout@v1
10-
- uses: actions/setup-node@v1
11-
with:
12-
node-version: "14.x"
13-
- name: Setup Testing Infra
14-
run: |
15-
cd test
16-
npm install
17-
18-
- name: "CommonJS Test"
19-
run: |
20-
cd test/cjs
21-
npm run test
22-
23-
- name: "ES Modules Test"
24-
run: |
25-
cd test/esm-node-native
26-
npm run test
27-
28-
- name: "Rollup Tree-shaking Test"
29-
run: |
30-
cd test/rollup-modules
31-
npm run test
32-
33-
- name: "Webpack Tree-shaking Test"
34-
run: |
35-
cd test/webpack-modules
36-
npm run test
37-
38-
- name: "Snowpack Tree-shaking Test"
39-
run: |
40-
cd test/snowpack-modules
41-
npm run test
22+
- uses: actions/checkout@v2
23+
24+
- name: Use node version ${{ matrix.node-version }}
25+
uses: actions/setup-node@v1
26+
with:
27+
node-version: ${{ matrix.node-version }}
28+
29+
- name: Setup Testing Infra
30+
run: |
31+
cd test
32+
npm install
33+
34+
- name: "CommonJS Test"
35+
run: |
36+
cd test/cjs
37+
npm run test
38+
39+
- name: "ES Modules Test"
40+
run: |
41+
cd test/esm-node-native
42+
npm run test
43+
if: ${{ matrix.node-version == "14.x" }}
44+
45+
- name: "Validate ES Modules == CommonJS"
46+
run: |
47+
cd test/validateModuleExportsMatchCommonJS
48+
npm run test
49+
if: ${{ matrix.node-version == "14.x" }}
50+
51+
- name: "Rollup Tree-shaking Test"
52+
run: |
53+
cd test/rollup-modules
54+
npm run test
55+
56+
- name: "Webpack Tree-shaking Test"
57+
run: |
58+
cd test/webpack-modules
59+
npm run test
60+
61+
- name: "Snowpack Tree-shaking Test"
62+
run: |
63+
cd test/snowpack-modules
64+
npm run test

.npmignore

+1
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
bower.json
44
docs
55
test
6+
.npmrc

.npmrc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

test/.gitignore

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,2 @@
11
package-lock.json
2-
rollup-modules/output
3-
webpack-modules/dist
4-
snowpack-modules/build
2+
*/build

test/cjs/index.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
1-
const { __awaiter } = require("tslib");
2-
3-
const testFunction = (textToPrint) => __awaiter(void 0, void 0, void 0, function* () {
4-
console.log(`State: ${textToPrint}`);
5-
});
6-
7-
testFunction("Works")
1+
const tslib = require("tslib");
2+
if (typeof tslib.__awaiter !== "function") throw new Error("Missing expected helper __awaiter");

test/esm-node-native/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
import { __awaiter } from "tslib";
2-
3-
export const testFunction = (textToPrint) => __awaiter(void 0, void 0, void 0, function* () {
4-
console.log(`State: ${textToPrint}`);
5-
});
6-
7-
testFunction("Works")
2+
if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");

test/rollup-modules/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
import { __awaiter } from "tslib";
2-
3-
export const testFunction = (textToPrint) => __awaiter(void 0, void 0, void 0, function* () {
4-
console.log(`State: ${textToPrint}`);
5-
});
6-
7-
testFunction("Works")
2+
if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");

test/rollup-modules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"scripts": {
3-
"test": "../node_modules/.bin/rollup -c rollup.config.js && node output/index.js"
3+
"test": "../node_modules/.bin/rollup -c rollup.config.js && node build/index.js"
44
}
55
}

test/rollup-modules/rollup.config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
33
export default {
44
input: 'index.js',
55
output: {
6-
dir: 'output',
6+
dir: 'build',
77
format: 'cjs'
88
},
99
plugins: [nodeResolve()]

test/snowpack-modules/index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,2 @@
11
import { __awaiter } from "tslib";
2-
3-
export const testFunction = (textToPrint) => __awaiter(void 0, void 0, void 0, function* () {
4-
console.log(`State: ${textToPrint}`);
5-
});
6-
7-
testFunction("Works")
2+
if (typeof __awaiter !== "function") throw new Error("Missing expected helper __awaiter");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// When on node 14, it validates that all of the commonjs exports
2+
// are correctly re-exported for es modules importers.
3+
4+
const nodeMajor = Number(process.version.split(".")[0].slice(1))
5+
if (nodeMajor < 14) {
6+
console.log("Skipping because node does not support module exports.")
7+
process.exit(0)
8+
}
9+
10+
// ES Modules import via the ./modules folder
11+
import * as esTSLib from "../../modules/index.js"
12+
13+
// Force a commonjs resolve
14+
import { createRequire } from "module";
15+
const commonJSTSLib = createRequire(import.meta.url)("../../tslib.js");
16+
17+
for (const key in commonJSTSLib) {
18+
if (commonJSTSLib.hasOwnProperty(key)) {
19+
if(!esTSLib[key]) throw new Error(`ESModules is missing ${key} - it needs to be re-exported in ./modules/index.js`)
20+
}
21+
}
22+
23+
console.log("All exports in commonjs are available for es module consumers.")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "module",
3+
"scripts": {
4+
"test": "node index.js"
5+
}
6+
}

test/webpack-modules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"scripts": {
3-
"test": "../node_modules/.bin/webpack && node dist/main.js"
3+
"test": "../node_modules/.bin/webpack && node build/main.js"
44
}
55
}
+11-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
module.exports = {
1+
const path = require('path');
2+
3+
/** @type {import("webpack").Configuration} */
4+
const config = {
25
mode: "production",
3-
entry: "./index"
6+
entry: "./index",
7+
output: {
8+
path: path.join(process.cwd(), 'build')
9+
}
10+
411
}
12+
13+
module.exports = config

0 commit comments

Comments
 (0)