@companion-module/tools 2.1.0 → 2.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.2.0](https://github.com/bitfocus/companion-module-tools/compare/v2.1.1...v2.2.0) (2025-03-06)
4
+
5
+
6
+ ### Features
7
+
8
+ * add --prerelease flag ([de5cf7d](https://github.com/bitfocus/companion-module-tools/commit/de5cf7d29c81fd8695773b38dcb560a814d311af))
9
+ * changed default output of build script to ${package}-${version}.tgz. Added flag -l keeping the legacy behaviour with fileoutput pkg.tgz ([#57](https://github.com/bitfocus/companion-module-tools/issues/57)) ([260a0ff](https://github.com/bitfocus/companion-module-tools/commit/260a0ff61c66611821fc66a5dfbd45c44ec08de6))
10
+ * user definable build filename ([199a9bd](https://github.com/bitfocus/companion-module-tools/commit/199a9bd11c01d0b0e6c8007ca951cc00591b9fad))
11
+
12
+ ## [2.1.1](https://github.com/bitfocus/companion-module-tools/compare/v2.1.0...v2.1.1) (2024-12-17)
13
+
14
+
15
+ ### Bug Fixes
16
+
17
+ * add tsconfig for node22 ([8e0a7b1](https://github.com/bitfocus/companion-module-tools/commit/8e0a7b1d29e5f17d7df18d20f487c452797b7d38))
18
+
3
19
  ## [2.1.0](https://github.com/bitfocus/companion-module-tools/compare/v2.0.4...v2.1.0) (2024-09-23)
4
20
 
5
21
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companion-module/tools",
3
- "version": "2.1.0",
3
+ "version": "2.2.0",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -26,16 +26,17 @@
26
26
  "webpack.*"
27
27
  ],
28
28
  "dependencies": {
29
- "@eslint/js": "^9.10.0",
30
- "eslint-config-prettier": "^9.1.0",
31
- "eslint-plugin-n": "^17.10.2",
32
- "eslint-plugin-prettier": "^5.2.1",
29
+ "@eslint/js": "^9.19.0",
30
+ "eslint-config-prettier": "^10.0.1",
31
+ "eslint-plugin-n": "^17.15.1",
32
+ "eslint-plugin-prettier": "^5.2.3",
33
33
  "find-up": "^7.0.0",
34
34
  "parse-author": "^2.0.0",
35
+ "semver": "^7.7.1",
35
36
  "tar": "^7.4.3",
36
- "webpack": "^5.94.0",
37
- "webpack-cli": "^5.1.4",
38
- "zx": "^8.1.6"
37
+ "webpack": "^5.97.1",
38
+ "webpack-cli": "^6.0.1",
39
+ "zx": "^8.3.2"
39
40
  },
40
41
  "peerDependencies": {
41
42
  "@companion-module/base": "^1.11.0",
@@ -56,9 +57,9 @@
56
57
  },
57
58
  "devDependencies": {
58
59
  "@types/eslint": "^9.6.1",
59
- "eslint": "^9.10.0",
60
- "prettier": "^3.3.3",
61
- "typescript-eslint": "^8.5.0"
60
+ "eslint": "^9.19.0",
61
+ "prettier": "^3.4.2",
62
+ "typescript-eslint": "^8.23.0"
62
63
  },
63
- "packageManager": "yarn@4.4.1"
64
+ "packageManager": "yarn@4.5.3"
64
65
  }
package/scripts/build.js CHANGED
@@ -8,11 +8,21 @@ import { findUp } from 'find-up'
8
8
  import * as tar from 'tar'
9
9
  import { validateManifest } from '@companion-module/base'
10
10
  import { createRequire } from 'module'
11
+ import * as semver from 'semver'
11
12
 
12
13
  if (process.platform === 'win32') {
13
14
  usePowerShell() // to enable powershell
14
15
  }
15
16
 
17
+ if (argv.help) {
18
+ console.log('Usage: build.js [--dev] [--prerelease]')
19
+ console.log('Builds the companion module')
20
+ console.log(' --dev: Build in development mode. This will not minify the code, making it easier to debug.')
21
+ console.log(' --prerelease: Build in prerelease mode. This gets added as metadata to the manifest')
22
+ console.log(' --output <filename>: Output to a specific filename, without a file extension')
23
+ process.exit(0)
24
+ }
25
+
16
26
  const require = createRequire(import.meta.url)
17
27
 
18
28
  async function findModuleDir(cwd) {
@@ -35,6 +45,11 @@ console.log(`Framework path: ${frameworkDir}`)
35
45
  // clean old
36
46
  await fs.remove('pkg')
37
47
 
48
+ // create new
49
+ await fs.mkdir(`pkg`)
50
+
51
+ const packageBaseDir = path.join('pkg')
52
+
38
53
  const webpackArgs = {
39
54
  ROOT: moduleDir,
40
55
  }
@@ -53,7 +68,7 @@ await $`npx webpack -c ${webpackConfig} ${webpackArgsArray}`
53
68
  $.cwd = undefined
54
69
 
55
70
  // copy in the metadata
56
- await fs.copy('companion', 'pkg/companion')
71
+ await fs.copy('companion', path.join(packageBaseDir, 'companion'))
57
72
 
58
73
  const srcPackageJson = JSON.parse(await fs.readFile(path.resolve('./package.json')))
59
74
  const frameworkPackageJson = JSON.parse(await fs.readFile(path.join(frameworkDir, 'package.json')))
@@ -64,7 +79,13 @@ manifestJson.runtime.entrypoint = '../main.js'
64
79
  manifestJson.version = srcPackageJson.version
65
80
  manifestJson.runtime.api = 'nodejs-ipc'
66
81
  manifestJson.runtime.apiVersion = frameworkPackageJson.version
67
- await fs.writeFile(path.resolve('./pkg/companion/manifest.json'), JSON.stringify(manifestJson))
82
+
83
+ // Bake in the prerelease flag if using module-base which is new enough
84
+ if (semver.gt(manifestJson.runtime.apiVersion, '1.12.0-0')) {
85
+ manifestJson.isPreRelease = !!argv.prerelease
86
+ }
87
+
88
+ await fs.writeFile(path.join(packageBaseDir, 'companion/manifest.json'), JSON.stringify(manifestJson))
68
89
 
69
90
  // Make sure the manifest is valid
70
91
  try {
@@ -113,13 +134,13 @@ if (fs.existsSync(webpackExtPath)) {
113
134
 
114
135
  // Copy across any prebuilds that can be loaded corectly
115
136
  if (webpackExt.prebuilds) {
116
- await fs.mkdir('pkg/prebuilds')
137
+ await fs.mkdir(path.join(packageBaseDir, 'prebuilds'))
117
138
 
118
139
  for (const lib of webpackExt.prebuilds) {
119
140
  const srcDir = await findModuleDir(require.resolve(lib))
120
141
  const dirs = await fs.readdir(path.join(srcDir, 'prebuilds'))
121
142
  for (const dir of dirs) {
122
- await fs.copy(path.join(srcDir, 'prebuilds', dir), path.join('pkg/prebuilds', dir))
143
+ await fs.copy(path.join(srcDir, 'prebuilds', dir), path.join(packageBaseDir, 'prebuilds', dir))
123
144
  }
124
145
  }
125
146
  }
@@ -132,7 +153,7 @@ if (fs.existsSync(webpackExtPath)) {
132
153
  })
133
154
 
134
155
  for (const file of files) {
135
- await fs.copy(file, path.join('pkg', path.basename(file)), {
156
+ await fs.copy(file, path.join(packageBaseDir, path.basename(file)), {
136
157
  overwrite: false,
137
158
  })
138
159
  }
@@ -158,8 +179,8 @@ if (webpackConfigJson.node?.__dirname === true) {
158
179
 
159
180
  const prebuildsDir = path.join(thisPath, 'prebuilds')
160
181
  if (dirPkgJson.dependencies?.['node-gyp-build'] && fs.existsSync(prebuildsDir)) {
161
- fs.mkdirpSync(path.join('pkg', thisPath))
162
- fs.copySync(prebuildsDir, path.join('pkg', prebuildsDir))
182
+ fs.mkdirpSync(path.join(packageBaseDir, thisPath))
183
+ fs.copySync(prebuildsDir, path.join(packageBaseDir, prebuildsDir))
163
184
 
164
185
  console.log('copying node-gyp-build prebuilds from', thisPath)
165
186
  }
@@ -171,20 +192,28 @@ if (webpackConfigJson.node?.__dirname === true) {
171
192
 
172
193
  // Write the package.json
173
194
  // packageJson.bundleDependencies = Object.keys(packageJson.dependencies)
174
- await fs.writeFile('pkg/package.json', JSON.stringify(packageJson))
195
+ await fs.writeFile(path.join(packageBaseDir, 'package.json'), JSON.stringify(packageJson))
175
196
 
176
197
  // If we found any depenendencies for the pkg, install them
177
198
  if (Object.keys(packageJson.dependencies).length) {
178
- await fs.writeFile('pkg/yarn.lock', '')
179
- await $`yarn --cwd pkg install --no-immutable`
199
+ await fs.writeFile(path.join(packageBaseDir, 'yarn.lock'), '')
200
+ await $`yarn --cwd ${packageBaseDir} install --no-immutable`
180
201
  }
181
202
 
182
203
  // Create tgz of the build
204
+ let tgzFile = `${manifestJson.name}-${manifestJson.version}`
205
+ if (typeof argv['output'] === 'string') {
206
+ // -o flag, to allow legacy behaviour creating pkg.tgz output
207
+ tgzFile = argv['output']
208
+ }
209
+ tgzFile += '.tgz'
210
+ console.log('Writing compressed package output to', tgzFile)
211
+
183
212
  await tar
184
213
  .create(
185
214
  {
186
215
  gzip: true,
187
216
  },
188
- ['pkg'],
217
+ [packageBaseDir],
189
218
  )
190
219
  .pipe(fs.createWriteStream('pkg.tgz'))
@@ -0,0 +1,30 @@
1
+ {
2
+ "compilerOptions": {
3
+ "module": "commonjs",
4
+ "target": "es2022",
5
+ "noImplicitAny": true,
6
+ "moduleResolution": "node",
7
+ "sourceMap": true,
8
+ "paths": {
9
+ "*": ["../node_modules/*"]
10
+ },
11
+ "declaration": false,
12
+ "importHelpers": false,
13
+ "listFiles": false,
14
+ "traceResolution": false,
15
+ "pretty": true,
16
+ "lib": ["es2023"],
17
+ "types": ["node"],
18
+ "strict": true,
19
+ "alwaysStrict": false,
20
+ "forceConsistentCasingInFileNames": true,
21
+ "noFallthroughCasesInSwitch": true,
22
+ "noImplicitReturns": true,
23
+ "noUnusedLocals": true,
24
+ "noUnusedParameters": true,
25
+ "skipLibCheck": true,
26
+ "allowSyntheticDefaultImports": true,
27
+ "esModuleInterop": true
28
+ },
29
+ "compileOnSave": false
30
+ }
@@ -41,7 +41,7 @@ module.exports = async (env) => {
41
41
  experiments: {
42
42
  topLevelAwait: true,
43
43
  },
44
- optimization: {
44
+ optimization: {
45
45
  minimize: !webpackExt.disableMinifier,
46
46
  },
47
47
  module: {
@@ -66,7 +66,7 @@ optimization: {
66
66
  node: webpackExt.useOriginalStructureDirname
67
67
  ? {
68
68
  __dirname: true,
69
- }
69
+ }
70
70
  : undefined,
71
71
  }
72
72
  }