Skip to content

Commit

Permalink
Bump dependencies (#23)
Browse files Browse the repository at this point in the history
* Add update script

* Add tests

* Fix syntax error

* Fix syntax error

* Upload all tests

* Add trigger

* Update name

* Update build script

* Update artifact name

* Update folder

* Update tarball filename

* Merge Dockerfile

* Add LTS/latest and debug

* Reduce versions

* Separate tests

* Fix build script

* Fix syntax error

* Fix build script

* Separate RUN commands

* Remove unneeded files

* Update deps

* Update read-pkg-up

* Fix test

* Fix expected.txt

* Change directory before test

* Add more tests

* Add esbuild

* Update expected

* Add npm-version

* Fix build-arg

* Rename matrix

* Add webpack-esm

* Add rollup

* Add 12.x

* Reduce test files

* Clean up

* Move terser to devDependencies

* Better task names

* Update version of @babel/runtime

* Add global test

* Only upload once

* Add PR template

* Add entry

* Add summary section
  • Loading branch information
compulim committed Feb 28, 2022
1 parent af51e8d commit 64662a9
Show file tree
Hide file tree
Showing 42 changed files with 1,395 additions and 1,999 deletions.
27 changes: 27 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
## Summary

<!-- Explain the purpose of this pull request in one line. -->

## Changelog

### Fixed/Added/Changed

<!-- Copy and paste the entry from CHANGELOG.md. -->

## Design considerations

<!-- Explains how we come up with the final design and design candidates (if any). -->

## Specific changes

<!-- Explains what changed in details. -->

-

## Reminders

<!-- Checks all boxes even if it is irrelevant to this pull request. -->

- [ ] I have updated `CHANGELOG.md`
- [ ] I have added tests for new code
- [ ] I have updated documentations
96 changes: 96 additions & 0 deletions .github/workflows/docker-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Pull request validation

on:
pull_request:

workflow_dispatch:
inputs:
version:
description: 'Version'
required: true
default: 'master'

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
node-version: ['12', '14', '16']
npm-version: [default, latest]

steps:
- name: Checking out for ${{ github.ref }}
uses: actions/checkout@v2

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}

- name: Install latest NPM
if: ${{ matrix.npm-version == 'latest' }}
run: npm install -g npm

- run: |
npm install
npm run prepublishOnly
npm pack
- name: Upload end-to-end tests
uses: actions/upload-artifact@v2
if: ${{ matrix.node-version == '16' && matrix.npm-version == 'default' }}
with:
name: e2e-tests
path: '__e2e__/**/*'

- name: Upload package tarball
uses: actions/upload-artifact@v2
if: ${{ matrix.node-version == '16' && matrix.npm-version == 'default' }}
with:
name: package
path: '*.tgz'

test:
needs: build
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
resolver:
- esbuild
- node-commonjs
- node-esm
- node-global
- rollup
- webpack4-commonjs
- webpack4-esm
- webpack5-commonjs
- webpack5-esm
node-version: ['12', '14', '16']
npm-version: [default, latest]

steps:
- name: Download end-to-end tests
uses: actions/download-artifact@v2
with:
name: e2e-tests

- name: Download package tarball
uses: actions/download-artifact@v2
with:
name: package

- name: Build test image
run: |
cd ${{ matrix.resolver }}
cp ../*.tgz .
ls -la
docker build --build-arg NODE_VERSION=${{ matrix.node-version }} --build-arg NPM_VERSION=${{ matrix.npm-version }} --file Dockerfile --tag test-image .
- name: Run test
run: |
cd ${{ matrix.resolver }}
docker run --name test-container test-image > actual.txt
diff expected.txt actual.txt
98 changes: 0 additions & 98 deletions .github/workflows/e2e-test.yml

This file was deleted.

15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Updated end-to-end tests, by [@compulim](https://github.com/compulim), in PR [#23](https://github.com/compulim/p-defer-es5/pull/23)
- Using Docker to isolate tests
- Test against different combinations of Node.js, NPM, and resolvers
- Bumped dependencies, by [@compulim](https://github.com/compulim), in PR [#23](https://github.com/compulim/p-defer-es5/pull/23)
- [`@babel/cli@7.17.6`](https://npmjs.com/package/@babel/cli)
- [`@babel/core@7.17.5`](https://npmjs.com/package/@babel/core)
- [`@babel/plugin-transform-runtime@7.17.0`](https://npmjs.com/package/@babel/plugin-transform-runtime)
- [`@babel/preset-env@7.16.11`](https://npmjs.com/package/@babel/preset-env)
- [`@babel/runtime-corejs3@7.17.2`](https://npmjs.com/package/@babel/runtime-corejs3)
- [`esbuild@0.14.23`](https://npmjs.com/package/esbuild)
- [`read-pkg-up@9.1.0`](https://npmjs.com/package/read-pkg-up)
- [`terser@5.11.0`](https://npmjs.com/package/terser)

## [2.0.0] - 2021-07-20

### Added
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

This package is based on [`p-defer`](https://npmjs.com/package/p-defer). It did not contains an ES5 module. Importing the module directly or indirectly may break web apps running on ES5 browsers.

On install, this package will transpile your version of `p-defer` to make it compatible with ES5 browsers.
On `npm install`, this package will transpile your version of `p-defer` to make it compatible with ES5 browsers. Then in your code, you use `p-defer-es5` instead of `p-defer`.

Package authors should consider importing this package instead of `p-defer`, so your packages will not break your users due to having `p-defer` as a transient dependency.

Expand All @@ -24,7 +24,7 @@ You can also use it in HTML:

## How it works

On `postinstall`, this package will run Babel and Webpack to transpile `p-defer` into a single file.
On `postinstall`, this package will run `esbuild` to bundle `p-defer` into a single file. Then run Babel to transpile it for ES5.

This package peer-depends on `p-defer`. Thus, you can select your own version of `p-defer`.

Expand All @@ -44,7 +44,7 @@ Be sure to include the original license and continue to depends on the package t

### Modify your bundler configuration

Webpack do not transpile code under `/node_modules/` unless specified explicitly. You can modify `webpack.config.js` to include `/node_modules/p-defer/` and use `babel-loader` to transpile it on-the-fly.
Some bundlers is configured not to transpile code under `/node_modules/` unless specified explicitly. You can modify bundler configuration to include `/node_modules/p-defer/` and use Babel to transpile it while bundling.

## Contributions

Expand Down
1 change: 1 addition & 0 deletions __e2e__/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/**/p-defer-es5-*.tgz
21 changes: 21 additions & 0 deletions __e2e__/esbuild/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
ARG NODE_VERSION=16

FROM node:$NODE_VERSION-alpine
ARG NPM_VERSION

WORKDIR /var/test/
COPY * /var/test/

RUN if [[ "$NPM_VERSION" == "latest" ]] ; then npm install -g npm ; fi

RUN node --version
RUN npm --version

RUN npm init --yes
RUN npm install p-defer
RUN npm install ./`ls *.tgz`

# The lowest version supported by ESBuild is "es2016".
RUN npx esbuild ./index.js --bundle --minify --outfile=./dist/main.js --target=es2016

ENTRYPOINT node ./dist/main.js
1 change: 1 addition & 0 deletions __e2e__/esbuild/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!
17 changes: 17 additions & 0 deletions __e2e__/esbuild/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// When bundling with esbuild:
// - If we "import", it load ESM from "p-defer-es5/module". The default imported object is () => any.
// - If we "require", it load CJS from "p-defer-es5/main". The default imported object is () => any.

// When bundling with Webpack:
// - Nomatter we "import" or "require", it always load ESM from "p-defer-es5/module", based on the "webpack.config.json/mainFields".
// - If we "import", the default imported object is () => any.
// - If we "require", the default imported object is { default: () => any }.
// - If we "require" and "mainFields" is "main", the default imported object is () => any.

const createDeferred = require('p-defer-es5');

const { promise, resolve } = createDeferred();

setTimeout(() => resolve('Hello, World!'), 0);

promise.then(result => console.log(result));
18 changes: 18 additions & 0 deletions __e2e__/node-commonjs/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG NODE_VERSION=16

FROM node:$NODE_VERSION-alpine
ARG NPM_VERSION

WORKDIR /var/test/
COPY * /var/test/

RUN if [[ "$NPM_VERSION" == "latest" ]] ; then npm install -g npm ; fi

RUN node --version
RUN npm --version

RUN npm init --yes
RUN npm install p-defer
RUN npm install ./`ls *.tgz`

ENTRYPOINT node ./index.js
1 change: 1 addition & 0 deletions __e2e__/node-commonjs/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!
7 changes: 7 additions & 0 deletions __e2e__/node-commonjs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const createDeferred = require('p-defer-es5');

const { promise, resolve } = createDeferred();

setTimeout(() => resolve('Hello, World!'), 0);

promise.then(console.log.bind(console));
18 changes: 18 additions & 0 deletions __e2e__/node-esm/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG NODE_VERSION=16

FROM node:$NODE_VERSION-alpine
ARG NPM_VERSION

WORKDIR /var/test/
COPY * /var/test/

RUN if [[ "$NPM_VERSION" == "latest" ]] ; then npm install -g npm ; fi

RUN node --version
RUN npm --version

RUN npm init --yes
RUN npm install p-defer
RUN npm install ./`ls *.tgz`

ENTRYPOINT node ./index.mjs
1 change: 1 addition & 0 deletions __e2e__/node-esm/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!
7 changes: 7 additions & 0 deletions __e2e__/node-esm/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import createDeferred from 'p-defer-es5';

const { promise, resolve } = createDeferred();

setTimeout(() => resolve('Hello, World!'), 0);

promise.then(console.log.bind(console));
18 changes: 18 additions & 0 deletions __e2e__/node-global/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ARG NODE_VERSION=16

FROM node:$NODE_VERSION-alpine
ARG NPM_VERSION

WORKDIR /var/test/
COPY * /var/test/

RUN if [[ "$NPM_VERSION" == "latest" ]] ; then npm install -g npm ; fi

RUN node --version
RUN npm --version

RUN npm init --yes
RUN npm install p-defer
RUN npm install ./`ls *.tgz`

ENTRYPOINT node ./index.js
1 change: 1 addition & 0 deletions __e2e__/node-global/expected.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello, World!

0 comments on commit 64662a9

Please sign in to comment.