Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build: migrate to ES Modules #2864

Draft
wants to merge 17 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/actions/zwave-js-bot/main.js
Expand Up @@ -30,7 +30,7 @@ async function publishPr() {
let newVersion;
try {
// Build it
await exec.exec("yarn", ["run", "build:full"]);
await exec.exec("yarn", ["run", "build"]);

// Configure git
await exec.exec("git", ["config", "user.email", "bot@zwave-js.io"]);
Expand Down
44 changes: 11 additions & 33 deletions .github/workflows/test-and-release.yml
Expand Up @@ -138,44 +138,22 @@ jobs:
- name: Compile TypeScript code
run: yarn run build

# Test that the generated packages are ok
- if: matrix.node-version == '10.x'
name: Import main entry point (CommonJS)
run: yarn node -e 'require("zwave-js")'

- if: matrix.node-version != '10.x'
name: Import main entry point (ESM)
run: yarn node --input-type=module --es-module-specifier-resolution=node -e 'import "zwave-js"'

- name: Run component tests
run: yarn run test:ci
env:
CI: true

# ===================

# Test that the generated packages are ok
test-package:
if: contains(github.event.head_commit.message, '[skip ci]') == false

runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x] # This should be LTS

steps:
- name: Checkout code
uses: actions/checkout@v2

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

- name: Install dependencies
run: yarn install --immutable

# Do a full build so the package files are regenerated
- name: Compile TypeScript code
run: yarn run build:full

- name: Import main entry point
run: yarn node -e 'require("./packages/zwave-js")'

# ===================

# Generate coverage reports when the unit tests have succeeded
coverage:
# Trigger this step only on pushes, because the job often fails for pull requests
Expand Down Expand Up @@ -227,7 +205,7 @@ jobs:
github.event_name == 'push' &&
startsWith(github.ref, 'refs/tags/v')

needs: [lint, lint-zwave, unit-tests, test-package]
needs: [lint, lint-zwave, unit-tests]

runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -264,7 +242,7 @@ jobs:
run: yarn install --immutable

- name: Create a clean build
run: yarn run build:full
run: yarn run build

- name: Publish packages to npm
env:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -16,7 +16,7 @@ node_modules/
/.nyc_output
coverage/

# npm packet files
# npm package files
zwave-js-*.tgz

# ZWave cache
Expand Down
78 changes: 1 addition & 77 deletions .vscode/settings.json
Expand Up @@ -16,7 +16,6 @@
"coverage/": true,
".*": false,
"**/node_modules/": true,
"**/*.test.js": true,
".nyc_output": true,
"**/coverage/": true,
"**/*.map": true,
Expand All @@ -25,86 +24,11 @@
"build": true,
"*.d.ts": true,
"*.map": true,
"CommandClass.js": true,
"Controller.js": true,
"Driver.js": true,
"Error.js": true,
"Node.js": true,
"Values.js": true,
"index.js": true,
"packages/core/Capabilities.js": true,
"packages/core/Consts.js": true,
"packages/core/Error.js": true,
"packages/core/Log.js": true,
"packages/core/Security.js": true,
"packages/core/Test.js": true,
"packages/core/Util.js": true,
"packages/core/Values.js": true,
"packages/core/index.js": true,
"**/build": true,
"**/*.tsbuildinfo": true,
"Utils.js": true,
"packages/core/Capabilities.d.ts": true,
"packages/core/Consts.d.ts": true,
"packages/core/Error.d.ts": true,
"packages/core/Log.d.ts": true,
"packages/core/Security.d.ts": true,
"packages/core/Test.d.ts": true,
"packages/core/Util.d.ts": true,
"packages/core/Values.d.ts": true,
"packages/core/index.d.ts": true,
"packages/zwave-js/CommandClass.d.ts": true,
"packages/zwave-js/CommandClass.js": true,
"packages/zwave-js/Controller.d.ts": true,
"packages/zwave-js/Controller.js": true,
"packages/zwave-js/Driver.d.ts": true,
"packages/zwave-js/Driver.js": true,
"packages/zwave-js/Error.d.ts": true,
"packages/zwave-js/Error.js": true,
"packages/zwave-js/Node.d.ts": true,
"packages/zwave-js/Node.js": true,
"packages/zwave-js/Utils.d.ts": true,
"packages/zwave-js/Utils.js": true,
"packages/zwave-js/Values.d.ts": true,
"packages/zwave-js/Values.js": true,
"packages/zwave-js/index.d.ts": true,
"packages/zwave-js/index.js": true,
"node_modules/zwave-js/CommandClass.d.ts": true,
"node_modules/zwave-js/CommandClass.js": true,
"node_modules/zwave-js/Controller.d.ts": true,
"node_modules/zwave-js/Controller.js": true,
"node_modules/zwave-js/Driver.d.ts": true,
"node_modules/zwave-js/Driver.js": true,
"node_modules/zwave-js/Error.d.ts": true,
"node_modules/zwave-js/Error.js": true,
"node_modules/zwave-js/Node.d.ts": true,
"node_modules/zwave-js/Node.js": true,
"node_modules/zwave-js/Utils.d.ts": true,
"node_modules/zwave-js/Utils.js": true,
"node_modules/zwave-js/Values.d.ts": true,
"node_modules/zwave-js/Values.js": true,
"node_modules/zwave-js/index.d.ts": true,
"node_modules/zwave-js/index.js": true,
"**/cache": true,
"packages/zwave-js/**/fingerprint.txt": true,
"node_modules/zwave-js/**/fingerprint.txt": true,
".husky/**/_": true,
"packages/*/package-lock.json": true,
".yarn/*": true,
".yarn/patches": false,
".yarn/releases": false,
".yarn/plugins": false,
".yarn/sdks": false,
".yarn/versions": false,
"**/.pnp.*": true,
"packages/*/cache": true,
"**/.tmp": true,
"**/.tmpoh/": true,
"**/.tmpozw/": true,
"**/.tmpzwa/": true,
"**/.secrets": true,
"**/.test-payloads": true,
"packages/config/config/devices/index.json": true
"node_modules/zwave-js/**/fingerprint.txt": true
},
"files.associations": {
"**/config/**/*.json": "jsonc"
Expand Down
2 changes: 1 addition & 1 deletion docs/development/implementing-cc.md
Expand Up @@ -28,7 +28,7 @@ Make sure you have the [project snippets](https://marketplace.visualstudio.com/i
- CCs that can set values for a given value ID must have a `SET_VALUE` API. There is no snippet for that yet, best check other CCs how they use it.
- CCs that can poll values for a given value ID must have a `POLL_VALUE` API. There is no snippet for that yet, best check other CCs how they use it.

> [!NOTE] At this point, you'll likely notice that the API class is not yet available through `node.commandClasses`. To fix that, you need to build the project once using `yarn run build:full`.
> [!NOTE] At this point, you'll likely notice that the API class is not yet available through `node.commandClasses`. To fix that, you need to build the project once using `yarn run build`.

1. Implement the interview procedure in the base class. This is defined for many CCs in the `SDS14223` document. The `zwccinterview` snippet generates some boilerplate for that, `zwccintreq` can be used to define which CCs must be interviewed before the current one.
Two things to keep in mind:
Expand Down
2 changes: 1 addition & 1 deletion docs/development/installing-from-github.md
Expand Up @@ -13,7 +13,7 @@ If you need to test changes from GitHub, e.g. a branch that fixes an issue you h
1. Install dependencies, compile the sources
```bash
yarn
yarn run build:full
yarn run build
```
1. Link the `zwave-js` packages into your repo:
1. If your repo is using `yarn v2`, execute this in your repo:
Expand Down
15 changes: 8 additions & 7 deletions package.json
Expand Up @@ -30,6 +30,7 @@
"@actions/core": "^1.4.0",
"@actions/exec": "^1.1.0",
"@actions/github": "^5.0.0",
"@alcalzone/esm2cjs": "^1.1.0",
"@alcalzone/jsonl-db": "^1.3.0",
"@alcalzone/release-script": "^2.2.0",
"@babel/core": "^7.14.6",
Expand All @@ -43,14 +44,13 @@
"@commitlint/config-conventional": "^12.1.4",
"@fimbul/mithotyn": "^0.24.0",
"@fimbul/wotan": "^0.24.0",
"@types/fs-extra": "^9.0.12",
"@tsconfig/node12": "^1.0.8",
"@types/jest": "^26.0.23",
"@types/node": "^15.12.5",
"@typescript-eslint/eslint-plugin": "^4.28.2",
"@typescript-eslint/parser": "^4.28.2",
"@zwave-js/config": "7.11.0",
"@zwave-js/core": "7.11.0",
"babel-jest": "^26.6.3",
"@zwave-js/config": "8.0.0-alpha.1",
"@zwave-js/core": "8.0.0-alpha.0",
"commitizen": "^4.2.4",
"coveralls": "^3.1.1",
"cz-conventional-changelog": "^3.3.0",
Expand All @@ -68,14 +68,15 @@
"reflect-metadata": "^0.1.13",
"ts-node": "^10.0.0",
"typescript": "^4.3.5",
"zwave-js": "7.11.0"
"zwave-js": "8.0.0-alpha.2"
},
"resolutions": {
"@ts-morph/common": "patch:@ts-morph/common@~0.10.0#.yarn/sdks/ts-morph/patch.diff"
},
"scripts": {
"build": "lerna run build --scope=zwave-js",
"build:full": "lerna run build --scope=\"@zwave-js/*\" && lerna run build_full",
"build": "lerna run build",
"deprecated": "node -p '\\\"\\\\n \\\\n \\\\033[31;1;4mThe \\\\\"build:full\\\\\" script has been deprecated. Use \\\\\"build\\\\\" instead!\\\\033[0m\\\\n \\\\n\\\"'",
"build:full": "yarn run deprecated && yarn run build",
"watch": "lerna run watch --parallel",
"test:reset": "jest --clear-cache",
"test:ts": "jest",
Expand Down
17 changes: 14 additions & 3 deletions packages/config/package.json
Expand Up @@ -6,8 +6,16 @@
"access": "public"
},
"keywords": [],
"main": "build/index.js",
"types": "build/index.d.ts",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"exports": {
".": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"./package.json": "./package.json"
},
"types": "build/esm/index.d.ts",
"files": [
"build/**/*.{js,d.ts,map}",
"config/"
Expand All @@ -32,13 +40,16 @@
"node": ">=v12.22.2"
},
"scripts": {
"build": "yarn ts maintenance/prebuild.ts && tsc -b tsconfig.build.json",
"prebuild": "yarn ts maintenance/prebuild.ts",
"build": "yarn prebuild && tsc -b tsconfig.build.json && yarn postbuild",
"postbuild": "yarn esm2cjs --in=build/esm --out=build/cjs -l error",
"clean": "tsc -b tsconfig.build.json --clean",
"watch": "yarn run build --watch --pretty",
"lint_config": "yarn ts maintenance/lintConfigFiles.ts",
"ts": "node -r esbuild-register"
},
"dependencies": {
"@alcalzone/esm2cjs": "^1.1.0",
"@zwave-js/core": "8.0.0-alpha.0",
"@zwave-js/shared": "8.0.0-alpha.0",
"alcalzone-shared": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/tsconfig.build.json
Expand Up @@ -3,7 +3,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build"
"outDir": "build/esm"
},
"references": [
{
Expand Down
24 changes: 17 additions & 7 deletions packages/core/package.json
Expand Up @@ -6,8 +6,16 @@
"access": "public"
},
"keywords": [],
"main": "build/index.js",
"types": "build/index.d.ts",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"exports": {
".": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"./package.json": "./package.json"
},
"types": "build/esm/index.d.ts",
"files": [
"build/**/*.{js,d.ts,map}"
],
Expand All @@ -30,7 +38,14 @@
"engines": {
"node": ">=v12.22.2"
},
"scripts": {
"build": "tsc -b tsconfig.build.json && yarn postbuild",
"postbuild": "yarn esm2cjs --in=build/esm --out=build/cjs -l error",
"clean": "yarn run build --clean",
"watch": "yarn run build --watch --pretty"
},
"dependencies": {
"@alcalzone/esm2cjs": "^1.1.0",
"@alcalzone/jsonl-db": "^1.3.0",
"@zwave-js/shared": "8.0.0-alpha.0",
"@zwave-js/winston-daily-rotate-file": "^4.5.6-0",
Expand All @@ -43,11 +58,6 @@
"winston": "^3.3.3",
"winston-transport": "*"
},
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "yarn run build --clean",
"watch": "yarn run build --watch --pretty"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/node": "^15.12.5",
Expand Down
10 changes: 3 additions & 7 deletions packages/core/tsconfig.build.json
Expand Up @@ -3,17 +3,13 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build/esm"
},
"references": [
{
"path": "../shared/tsconfig.build.json"
}
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
16 changes: 13 additions & 3 deletions packages/maintenance/package.json
Expand Up @@ -4,8 +4,16 @@
"description": "zwave-js: maintenance scripts",
"private": true,
"keywords": [],
"main": "build/index.js",
"types": "build/index.d.ts",
"main": "build/cjs/index.js",
"module": "build/esm/index.js",
"exports": {
".": {
"import": "./build/esm/index.js",
"require": "./build/cjs/index.js"
},
"./package.json": "./package.json"
},
"types": "build/esm/index.d.ts",
"files": [
"build/**/*.{js,d.ts,map}"
],
Expand All @@ -29,11 +37,13 @@
"node": ">=v12.22.2"
},
"scripts": {
"build": "tsc -b tsconfig.build.json",
"build": "tsc -b tsconfig.build.json && yarn postbuild",
"postbuild": "yarn esm2cjs --in=build/esm --out=build/cjs -l error",
"clean": "yarn run build --clean",
"watch": "yarn run build --watch --pretty"
},
"devDependencies": {
"@alcalzone/esm2cjs": "^1.1.0",
"@types/clipboardy": "^2",
"@types/fs-extra": "^9.0.11",
"@types/jest": "^26.0.23",
Expand Down