@companion-module/tools 1.3.2 → 1.4.1

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,19 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.4.1](https://github.com/bitfocus/companion-module-tools/compare/v1.4.0...v1.4.1) (2023-09-11)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * support for yarn3 ([6ab2458](https://github.com/bitfocus/companion-module-tools/commit/6ab2458c6148da0b1a305e377408b4cb64399dce))
9
+
10
+ ## [1.4.0](https://github.com/bitfocus/companion-module-tools/compare/v1.3.2...v1.4.0) (2023-08-22)
11
+
12
+
13
+ ### Features
14
+
15
+ * add option to disable minification. ([9f626f6](https://github.com/bitfocus/companion-module-tools/commit/9f626f69b82b9dc10b195ed076e01f794246f85b))
16
+
3
17
  ## [1.3.2](https://github.com/bitfocus/companion-module-tools/compare/v1.3.1...v1.3.2) (2023-06-20)
4
18
 
5
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@companion-module/tools",
3
- "version": "1.3.2",
3
+ "version": "1.4.1",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -25,17 +25,17 @@
25
25
  "dependencies": {
26
26
  "@typescript-eslint/eslint-plugin": "^5.59.9",
27
27
  "@typescript-eslint/parser": "^5.59.9",
28
- "eslint": "^8.42.0",
28
+ "eslint": "^8.47.0",
29
29
  "eslint-config-prettier": "^8.8.0",
30
- "eslint-plugin-n": "^16.0.0",
30
+ "eslint-plugin-n": "^16.0.2",
31
31
  "eslint-plugin-prettier": "^4.2.1",
32
32
  "find-up": "^6.3.0",
33
33
  "parse-author": "^2.0.0",
34
34
  "prettier": "^2.8.8",
35
35
  "tar": "^6.1.15",
36
- "webpack": "^5.86.0",
36
+ "webpack": "^5.88.2",
37
37
  "webpack-cli": "^5.1.4",
38
- "zx": "^7.2.2"
38
+ "zx": "^7.2.3"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "@companion-module/base": "^1.4.1"
package/scripts/build.js CHANGED
@@ -20,6 +20,7 @@ async function findModuleDir(cwd) {
20
20
  }
21
21
 
22
22
  // const toolsDir = path.join(__dirname, '..')
23
+ const moduleDir = process.cwd()
23
24
  const toolsDir = await findModuleDir(require.resolve('@companion-module/tools'))
24
25
  const frameworkDir = await findModuleDir(require.resolve('@companion-module/base'))
25
26
  console.log(`Building for: ${process.cwd()}`)
@@ -30,17 +31,21 @@ console.log(`Framework path: ${frameworkDir}`)
30
31
  // clean old
31
32
  await fs.remove('pkg')
32
33
 
33
- const webpackArgs = {}
34
- if (argv.dev || argv.debug) webpackArgs['env']= 'dev'
34
+ const webpackArgs = {
35
+ ROOT: moduleDir,
36
+ }
37
+ if (argv.dev || argv.debug) webpackArgs['dev'] = true
35
38
 
36
39
  const webpackArgsArray = []
37
40
  for (const [k, v] of Object.entries(webpackArgs)) {
38
- webpackArgsArray.push(`--${k}`, v)
41
+ webpackArgsArray.push(`--env`, v === true ? k : `${k}=${v}`)
39
42
  }
40
43
 
41
44
  // build the code
45
+ $.cwd = toolsDir
42
46
  const webpackConfig = path.join(toolsDir, 'webpack.config.cjs').replace(/\\/g, '/') // Fix slashes because windows is a pain
43
- await $`yarn webpack -c ${webpackConfig} ${webpackArgsArray}`
47
+ await $`yarn run -B webpack -c ${webpackConfig} ${webpackArgsArray}`
48
+ $.cwd = undefined
44
49
 
45
50
  // copy in the metadata
46
51
  await fs.copy('companion', 'pkg/companion')
@@ -140,16 +145,15 @@ if (webpackConfigJson.node?.__dirname === true) {
140
145
  if (dirPkgJson.dependencies?.['node-gyp-build'] && fs.existsSync(prebuildsDir)) {
141
146
  fs.mkdirpSync(path.join('pkg', thisPath))
142
147
  fs.copySync(prebuildsDir, path.join('pkg', prebuildsDir))
143
-
148
+
144
149
  console.log('copying node-gyp-build prebuilds from', thisPath)
145
150
  }
146
151
  }
147
152
  }
148
-
153
+
149
154
  copyNodeGypBuildPrebuilds('')
150
155
  }
151
156
 
152
-
153
157
  // Write the package.json
154
158
  // packageJson.bundleDependencies = Object.keys(packageJson.dependencies)
155
159
  await fs.writeFile('pkg/package.json', JSON.stringify(packageJson))
@@ -77,44 +77,3 @@ if (await fs.pathExists('HELP.md')) {
77
77
  if (await fs.pathExists('images')) await fs.move('images', path.join(manifestDir, 'images'))
78
78
  if (await fs.pathExists('documentation')) await fs.move('documentation', path.join(manifestDir, 'documentation'))
79
79
  }
80
-
81
- // for (const folder of dirs) {
82
- // if (folder.match(/companion-module-/) && !ignoreNames.includes(folder)) {
83
- // const moduleDir = path.join(outerDir, folder)
84
- // const moduleNewDir = path.join(outerManifest, folder)
85
- // const manifestDir = path.join(moduleNewDir, 'companion')
86
-
87
- //
88
- // await fs.mkdirp(manifestDir)
89
- // await fs.writeFile(path.join(manifestDir, 'manifest.json'), JSON.stringify(manifest, undefined, '\t'))
90
-
91
- // if (await fs.pathExists(( 'HELP.md'))) {
92
- // await fs.copy(( 'HELP.md'), path.join(manifestDir, 'HELP.md'))
93
-
94
- // // guess at what images might be needed by the help
95
- // if (await fs.pathExists(( 'images')))
96
- // await fs.copy(( 'images'), path.join(manifestDir, 'images'))
97
- // if (await fs.pathExists(( 'documentation')))
98
- // await fs.copy(( 'documentation'), path.join(manifestDir, 'documentation'))
99
- // }
100
-
101
- // await fs.writeFile(
102
- // path.join(outerEntrypoints, `${pkgJson.name}.cjs`),
103
- // `
104
- // global.modulePkg = require('companion-module-${pkgJson.name}/package.json')
105
- // global.moduleFactory = require('companion-module-${pkgJson.name}')
106
- // global.moduleName = "${pkgJson.name}"
107
- // import('../../dist/index.js')
108
- // `
109
- // )
110
- // }
111
- // }
112
-
113
- // console.log('Bundling code. This will take a couple of minutes')
114
- // await $`yarn webpack`
115
-
116
- // // trick node into treating them all as cjs
117
- // await fs.writeFile(`manifests/package.json`, '')
118
-
119
- // // const useDir = await fs.pathExists('./module/legacy')
120
- // // const baseDir = useDir ? './module/legacy' : './node_modules/companion-wrapped-module'
@@ -1,24 +1,26 @@
1
1
  const path = require('path')
2
2
 
3
- const frameworkDir = path.relative(process.cwd(), path.resolve('@companion-module/base'))
4
- const pkgJson = require(path.join(process.cwd(), 'package.json'))
3
+ module.exports = async (env) => {
4
+ if (!env.ROOT) throw new Error(`Missing ROOT`)
5
5
 
6
- if (!pkgJson.main) throw new Error(`Missing main in package.json`)
6
+ const frameworkDir = path.relative(env.ROOT, path.resolve('@companion-module/base'))
7
+ const pkgJson = require(path.join(env.ROOT, 'package.json'))
7
8
 
8
- let webpackExt = {}
9
- try {
10
- webpackExt = require(path.join(process.cwd(), 'build-config.cjs'))
9
+ if (!pkgJson.main) throw new Error(`Missing main in package.json`)
11
10
 
12
- console.log('Found additional webpack configuration')
13
- } catch (e) {
14
- // Ignore
15
- }
11
+ let webpackExt = {}
12
+ try {
13
+ webpackExt = require(path.join(env.ROOT, 'build-config.cjs'))
14
+
15
+ console.log('Found additional webpack configuration')
16
+ } catch (e) {
17
+ // Ignore
18
+ }
16
19
 
17
- let externalsExt = []
18
- if (Array.isArray(webpackExt.externals)) externalsExt = webpackExt.externals
19
- else if (webpackExt.externals) externalsExt = [webpackExt.externals]
20
+ let externalsExt = []
21
+ if (Array.isArray(webpackExt.externals)) externalsExt = webpackExt.externals
22
+ else if (webpackExt.externals) externalsExt = [webpackExt.externals]
20
23
 
21
- module.exports = async (env) => {
22
24
  return {
23
25
  entry: {
24
26
  main: './' + pkgJson.main, // path.join(frameworkDir, 'dist/entrypoint.js'),
@@ -28,9 +30,9 @@ module.exports = async (env) => {
28
30
  mode: env.dev ? 'development' : 'production',
29
31
  // devtool: env.dev ? undefined : 'source-map', // TODO - this would be nice, but I think the files have to be uploaded directly to sentry which is problematic...
30
32
  output: {
31
- path: path.resolve(process.cwd(), 'pkg'),
33
+ path: path.resolve(env.ROOT, 'pkg'),
32
34
  },
33
- context: path.resolve(process.cwd(), '.'),
35
+ context: path.resolve(env.ROOT, '.'),
34
36
  target: 'node',
35
37
  externals: [
36
38
  // Allow for custom externals
@@ -39,6 +41,9 @@ module.exports = async (env) => {
39
41
  experiments: {
40
42
  topLevelAwait: true,
41
43
  },
44
+ optimization: {
45
+ minimize: !webpackExt.disableMinifier,
46
+ },
42
47
  module: {
43
48
  rules: [
44
49
  // {
@@ -58,8 +63,10 @@ module.exports = async (env) => {
58
63
  // Let modules define additional plugins. Hopefully this won't conflict with anything we add
59
64
  ...(webpackExt.plugins || []),
60
65
  ],
61
- node: webpackExt.useOriginalStructureDirname ? {
62
- __dirname: true
63
- } : undefined,
66
+ node: webpackExt.useOriginalStructureDirname
67
+ ? {
68
+ __dirname: true,
69
+ }
70
+ : undefined,
64
71
  }
65
72
  }