Address feedback, and adds more tests

This commit is contained in:
Orta 2020-10-05 15:08:15 -04:00
Родитель c7980aeff4
Коммит 1007d3ec24
14 изменённых файлов: 104 добавлений и 63 удалений

83
.github/workflows/CI.yml поставляемый
Просмотреть файл

@ -1,41 +1,64 @@
name: CI
on: pull_request
on:
push:
branches:
- master
- release-*
pull_request:
branches:
- master
- release-*
jobs:
test:
ci:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [10.x, 12.x, 14.x]
steps:
- uses: actions/checkout@v1
- uses: actions/setup-node@v1
with:
node-version: "14.x"
- name: Setup Testing Infra
run: |
cd test
npm install
- uses: actions/checkout@v2
- name: Use node version ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: Setup Testing Infra
run: |
cd test
npm install
- name: "CommonJS Test"
run: |
cd test/cjs
npm run test
- name: "CommonJS Test"
run: |
cd test/cjs
npm run test
- name: "ES Modules Test"
run: |
cd test/esm-node-native
npm run test
- name: "ES Modules Test"
run: |
cd test/esm-node-native
npm run test
if: ${{ matrix.node-version == "14.x" }}
- name: "Rollup Tree-shaking Test"
run: |
cd test/rollup-modules
npm run test
- name: "Validate ES Modules == CommonJS"
run: |
cd test/validateModuleExportsMatchCommonJS
npm run test
if: ${{ matrix.node-version == "14.x" }}
- name: "Webpack Tree-shaking Test"
run: |
cd test/webpack-modules
npm run test
- name: "Rollup Tree-shaking Test"
run: |
cd test/rollup-modules
npm run test
- name: "Snowpack Tree-shaking Test"
run: |
cd test/snowpack-modules
npm run test
- name: "Webpack Tree-shaking Test"
run: |
cd test/webpack-modules
npm run test
- name: "Snowpack Tree-shaking Test"
run: |
cd test/snowpack-modules
npm run test

Просмотреть файл

@ -3,3 +3,4 @@
bower.json
docs
test
.npmrc

1
.npmrc Normal file
Просмотреть файл

@ -0,0 +1 @@
package-lock=false

4
test/.gitignore поставляемый
Просмотреть файл

@ -1,4 +1,2 @@
package-lock.json
rollup-modules/output
webpack-modules/dist
snowpack-modules/build
*/build

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

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

Просмотреть файл

@ -1,5 +1,5 @@
{
"scripts": {
"test": "../node_modules/.bin/rollup -c rollup.config.js && node output/index.js"
"test": "../node_modules/.bin/rollup -c rollup.config.js && node build/index.js"
}
}

Просмотреть файл

@ -3,7 +3,7 @@ import { nodeResolve } from '@rollup/plugin-node-resolve';
export default {
input: 'index.js',
output: {
dir: 'output',
dir: 'build',
format: 'cjs'
},
plugins: [nodeResolve()]

Просмотреть файл

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

Просмотреть файл

@ -0,0 +1,23 @@
// When on node 14, it validates that all of the commonjs exports
// are correctly re-exported for es modules importers.
const nodeMajor = Number(process.version.split(".")[0].slice(1))
if (nodeMajor < 14) {
console.log("Skipping because node does not support module exports.")
process.exit(0)
}
// ES Modules import via the ./modules folder
import * as esTSLib from "../../modules/index.js"
// Force a commonjs resolve
import { createRequire } from "module";
const commonJSTSLib = createRequire(import.meta.url)("../../tslib.js");
for (const key in commonJSTSLib) {
if (commonJSTSLib.hasOwnProperty(key)) {
if(!esTSLib[key]) throw new Error(`ESModules is missing ${key} - it needs to be re-exported in ./modules/index.js`)
}
}
console.log("All exports in commonjs are available for es module consumers.")

Просмотреть файл

@ -0,0 +1,6 @@
{
"type": "module",
"scripts": {
"test": "node index.js"
}
}

Просмотреть файл

@ -1,5 +1,5 @@
{
"scripts": {
"test": "../node_modules/.bin/webpack && node dist/main.js"
"test": "../node_modules/.bin/webpack && node build/main.js"
}
}

Просмотреть файл

@ -1,4 +1,13 @@
module.exports = {
const path = require('path');
/** @type {import("webpack").Configuration} */
const config = {
mode: "production",
entry: "./index"
entry: "./index",
output: {
path: path.join(process.cwd(), 'build')
}
}
module.exports = config