Skip to content

Commit

Permalink
[esinstall] enable native esm for node v12+ (#1093)
Browse files Browse the repository at this point in the history
* enable native mjs for node v14

* remove pika/pack for export maps to work

* update snowpack to remove @pika/pack as well

* update docs, meta info

* upgrade typescript to v4

Co-authored-by: Christopher Biscardi <[email protected]>
  • Loading branch information
FredKSchott and ChristopherBiscardi authored Sep 21, 2020
1 parent 0fe3dcc commit 20388e4
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 1,065 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ jobs:
run: |
yarn --ignore-engines
yarn build
yarn --ignore-engines --force
yarn test
env:
CI: true
13 changes: 6 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,21 @@ yarn

## Build after changes

Note: you will see warnings about `__dirname` and `require()` not being "a valid ESM global" when running `yarn build`. You can ignore these warnings.
Some packages in the repo are written in JavaScript, and require no build step. Others (like Snowpack itself) are written in TypeScript, and require a build step to run.

```bash
# Option 1: A one-time build step
yarn build
yarn --force # only needed after very first build; afterward can be skipped
```

#### Why is `yarn --force` needed?

Lerna allows us to use our local build of Snowpack which is key for testing any changes we make. Thanks to Lerna, when we run `yarn build`, the `snowpack` [executable script](https://docs.npmjs.com/files/package.json#bin) is built at `./snowpack/pkg/node-dist/index.bin.js`. The `--force` command generates the symlinks needed so that this new executable script gets used by all parts of the project. Now when you run tests in [create-snowpack-app templates](./create-snowpack-app), it knows to use the locally built symlinked version. This solves two major problems: it means you don't have tons of `node_modules` in subdirectories and also means you don’t need to publish Snowpack to npm to test your changes.
# Option 2: Start a persistent TypeScript watcher, recompiling on every change
# Recommended for active development, when many changes are required
yarn build:watch
```

## Run tests

```bash
yarn build
yarn --force
yarn test
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"@types/snowpack-env": "^2.3.0",
"prettier": "^2.0.5",
"snowpack": "^2.11.0",
"typescript": "^3.9.7"
"typescript": "^4.0.0"
},
"gitHead": "a01616bb0787d56cd782f94cecf2daa12c7594e4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"@types/snowpack-env": "^2.3.0",
"prettier": "^2.0.5",
"snowpack": "^2.11.0",
"typescript": "^3.9.7"
"typescript": "^4.0.0"
},
"gitHead": "a01616bb0787d56cd782f94cecf2daa12c7594e4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"jest": "^26.2.2",
"prettier": "^2.0.5",
"snowpack": "^2.11.0",
"typescript": "^3.9.7"
"typescript": "^4.0.0"
},
"gitHead": "a01616bb0787d56cd782f94cecf2daa12c7594e4"
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"snowpack": "^2.11.0",
"svelte-check": "^1.0.0",
"svelte-preprocess": "^4.0.8",
"typescript": "^3.9.7"
"typescript": "^4.0.0"
},
"gitHead": "a01616bb0787d56cd782f94cecf2daa12c7594e4"
}
2 changes: 1 addition & 1 deletion esinstall/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
pkg
lib
4 changes: 4 additions & 0 deletions esinstall/index.esm.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import Pkg from './lib/index.js';

export const printStats = Pkg.printStats;
export const install = Pkg.install;
23 changes: 8 additions & 15 deletions esinstall/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,17 @@
"url": "https://github.com/pikapkg/snowpack.git"
},
"publishConfig": {
"access": "public",
"directory": "pkg"
"access": "public"
},
"scripts": {
"build": "pika build",
"version": "pika build"
"build": "tsc",
"build:watch": "tsc --watch"
},
"types": "pkg/dist-types/index.d.ts",
"main": "pkg/dist-node/index.js",
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-build-node"
]
]
"types": "lib/index.d.ts",
"main": "lib/index.js",
"exports": {
"import": "./index.esm.mjs",
"require": "./lib/index.js"
},
"dependencies": {
"@rollup/plugin-alias": "^3.0.1",
Expand Down
10 changes: 5 additions & 5 deletions esinstall/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"include": ["src"],
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"outDir": "lib",
"module": "commonjs",
"target": "es2018",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true
},
"include": ["src/**/*", "@types/**/*"],
"exclude": ["node_modules"]
}
}
8 changes: 2 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"scripts": {
"bootstrap": "lerna bootstrap",
"build": "lerna run build --scope=esinstall --scope=snowpack",
"build:watch": "lerna run build:watch --parallel --scope=esinstall --scope=snowpack",
"publish": "lerna publish --no-private",
"format": "prettier --write '{snowpack,esinstall}/src/**/*.{ts,js}' '{test,plugins}/**/*.{ts,js}' '*.{js,json,md}' '**/*.{json,md}' '.github/**/*.{md,yml}' '!**/{_dist_,build,packages,pkg,TEST_BUILD_OUT,web_modules}/**' !test/create-snowpack-app/test-install",
"test": "jest --test-timeout=30000"
Expand All @@ -17,11 +18,6 @@
"test/esinstall/*"
],
"devDependencies": {
"@pika/pack": "^0.5.0",
"@pika/plugin-build-node": "^0.9.1",
"@pika/plugin-copy-assets": "^0.9.1",
"@pika/plugin-simple-bin": "^0.9.1",
"@pika/plugin-ts-standard-pkg": "^0.9.1",
"@types/babel__traverse": "^7.0.7",
"@types/cacache": "^12.0.1",
"@types/compressible": "^2.0.0",
Expand All @@ -42,7 +38,7 @@
"jest": "^26.2.2",
"lerna": "^3.22.1",
"prettier": "^2.0.5",
"typescript": "^3.9.7"
"typescript": "^4.0.0"
},
"prettier": {
"singleQuote": true,
Expand Down
2 changes: 1 addition & 1 deletion snowpack/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
node_modules
pkg
lib
19 changes: 19 additions & 0 deletions snowpack/index.bin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/usr/bin/env node
'use strict';

const ver = process.versions.node;
const majorVer = parseInt(ver.split('.')[0], 10);

if (majorVer < 10) {
console.error('Node version ' + ver + ' is not supported, please use Node.js 10.0 or higher.');
process.exit(1);
}

const cli = require('./lib/index.js');
const run = cli.run || cli.cli || cli.default;
run(process.argv).catch(function (error) {
console.error(`
${error.stack || error.message || error}
`);
process.exit(1);
});
42 changes: 8 additions & 34 deletions snowpack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,20 @@
"url": "https://github.com/pikapkg/snowpack.git"
},
"publishConfig": {
"access": "public",
"directory": "pkg"
"access": "public"
},
"scripts": {
"build": "pika build",
"version": "pika build"
},
"bin": {
"sp": "pkg/dist-node/index.bin.js",
"snowpack": "pkg/dist-node/index.bin.js"
"build": "tsc",
"build:watch": "tsc --watch"
},
"engines": {
"node": ">=10.19.0"
},
"@pika/pack": {
"pipeline": [
[
"@pika/plugin-ts-standard-pkg"
],
[
"@pika/plugin-copy-assets"
],
[
"@pika/plugin-build-node"
],
[
"@pika/plugin-simple-bin",
{
"bin": "sp",
"minNodeVersion": 10
}
],
[
"@pika/plugin-simple-bin",
{
"bin": "snowpack",
"minNodeVersion": 10
}
]
]
"main": "lib/index.js",
"types": "lib/index.d.ts",
"bin": {
"sp": "index.bin.js",
"snowpack": "index.bin.js"
},
"dependencies": {
"@babel/plugin-syntax-import-meta": "^7.10.4",
Expand Down
13 changes: 6 additions & 7 deletions snowpack/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
{
"include": ["src"],
"compilerOptions": {
"target": "es2020",
"module": "esnext",
"outDir": "lib",
"module": "commonjs",
"target": "es2018",
"moduleResolution": "node",
"esModuleInterop": true,
"strict": true,
"noImplicitAny": false,
"noUnusedLocals": true,
"noUnusedParameters": true,
"skipLibCheck": true,
"jsx": "react"
},
"include": ["src/**/*", "@types/**/*"],
"exclude": ["node_modules"]
"skipLibCheck": true
}
}
Loading

1 comment on commit 20388e4

@vercel
Copy link

@vercel vercel bot commented on 20388e4 Sep 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.