Skip to content

Commit

Permalink
build: use Node.js 12+ module exports instead of faked entry points (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
AlCalzone authored Jul 13, 2021
1 parent db9538c commit e6ee291
Show file tree
Hide file tree
Showing 25 changed files with 236 additions and 841 deletions.
2 changes: 1 addition & 1 deletion .github/actions/zwave-js-bot/main.js
Original file line number Diff line number Diff line change
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
39 changes: 6 additions & 33 deletions .github/workflows/test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,44 +138,17 @@ jobs:
- name: Compile TypeScript code
run: yarn run build

# Test that the generated packages are ok
- name: Import main entry point
run: yarn node -e 'require("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 +200,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 +237,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
13 changes: 11 additions & 2 deletions docs/getting-started/migrating-to-v8.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Migrating to v7
# Migrating to v8

<!-- In version 8.x, we [INSERT XYZ], leading to several breaking changes. -->
For version 8.x, we had several breaking changes lined up, so we also took the chance to sneak in a few more by reworking our dev environment.

Please follow this guide if you're migrating from v7. If migrating from v6, please see the v7 migration guide first.

Expand All @@ -9,6 +9,15 @@ Please follow this guide if you're migrating from v7. If migrating from v6, plea
We have migrated the repository to the latest version of `yarn`. This changes a few things, mainly regarding installing dependencies and editor support.
The repo is configured to automatically use the correct `typescript` dependency, but if anything goes wrong, please read [this](https://yarnpkg.com/getting-started/editor-sdks#vscode). Also check out the updated documentation on [developing locally / installing from GitHub](https://zwave-js.github.io/node-zwave-js/#/development/installing-from-github).

## Raise minimum supported Node.js version to 12.22

Node.js 10 has been EOL since April 2021 and many Node.js packages have dropped support since then. In order to be able to properly maintain `zwave-js`, we now need to drop support aswell going forward. We chose to raise the bar a bit further (to Node.js `12.22`) in order to make use of some new features.

## Change secondary exports to `package.json` subpath exports

Since Node.js 12 officially supports `package.json` subpath exports, we removed our hand-rolled build step that has been causing some weirdness when developing on Windows for a while.
Importing the secondary exports `zwave-js/Values` etc. should continue to work, but you won't be able to import internal paths like `zwave-js/build/lib` anymore. Make sure you import the official exports only.

## Skip querying user codes during the interview

We have changed the default interview behavior for the `User Code CC` to no longer query all user codes during the initial interview and calls to `refreshValues`. This is intended to help save device battery as some devices may have hundreds of user codes, leading to significant battery drain.
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,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 +67,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
3 changes: 2 additions & 1 deletion packages/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
"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",
"clean": "tsc -b tsconfig.build.json --clean",
"watch": "yarn run build --watch --pretty",
"lint_config": "yarn ts maintenance/lintConfigFiles.ts",
Expand Down
10 changes: 5 additions & 5 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@
"engines": {
"node": ">=v12.22.2"
},
"scripts": {
"build": "tsc -b tsconfig.build.json",
"clean": "yarn run build --clean",
"watch": "yarn run build --watch --pretty"
},
"dependencies": {
"@alcalzone/jsonl-db": "^1.3.0",
"@zwave-js/shared": "8.0.0-alpha.0",
Expand All @@ -43,11 +48,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
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build"
},
"references": [
{
"path": "../shared/tsconfig.build.json"
}
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
1 change: 0 additions & 1 deletion packages/maintenance/src/generateTypedDocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ export function findImportRanges(docFile: string): ImportRange[] {
const matches = [...docFile.matchAll(importRegex)];
return matches.map((match) => ({
index: match.index!,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
end: match.index! + match[0].length,
module: match.groups!.module,
symbol: match.groups!.symbol,
Expand Down
6 changes: 5 additions & 1 deletion packages/maintenance/src/prettier.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import * as path from "path";
import * as prettier from "prettier";

// Make the linter happy
export function formatWithPrettier(
filename: string,
sourceText: string,
): string {
let rootPath = __dirname.replace(/\\/g, "/");
rootPath = rootPath.substr(0, rootPath.lastIndexOf("/packages/"));

const prettierOptions = {
...require("../../../.prettierrc"),
...require(path.join(rootPath, ".prettierrc")),
// To infer the correct parser
filepath: filename,
};
Expand Down
10 changes: 3 additions & 7 deletions packages/maintenance/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build"
},
"references": [
{
"path": "../core/tsconfig.build.json"
}
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
10 changes: 3 additions & 7 deletions packages/shared/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,8 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build"
},
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
10 changes: 3 additions & 7 deletions packages/testing/tsconfig.build.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"rootDir": "src",
"outDir": "build",
"outDir": "build"
},
"references": [
{
"path": "../core/tsconfig.build.json"
}
],
"include": [
"src/**/*.ts"
],
"exclude": [
"src/**/*.test.ts",
]
"include": ["src/**/*.ts"],
"exclude": ["src/**/*.test.ts"]
}
Loading

0 comments on commit e6ee291

Please sign in to comment.