@transitive-sdk/utils-caps 0.1.3 → 0.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.
Files changed (2) hide show
  1. package/esbuild.js +29 -13
  2. package/package.json +1 -1
package/esbuild.js CHANGED
@@ -1,7 +1,7 @@
1
1
  const esbuild = require('esbuild');
2
2
  const fs = require('fs');
3
3
  const { execSync } = require('child_process');
4
- // const svgrPlugin = require('esbuild-plugin-svgr');
4
+
5
5
  const { getPackageVersionNamespace } = require('@transitive-sdk/utils');
6
6
 
7
7
  if (!process.env.npm_package_version || !process.env.npm_package_name) {
@@ -11,6 +11,7 @@ if (!process.env.npm_package_version || !process.env.npm_package_name) {
11
11
 
12
12
  const entryPoints = fs.readdirSync('./web', {withFileTypes: true})
13
13
  .filter(item => !item.isDirectory())
14
+ .filter(item => !item.isSymbolicLink())
14
15
  .filter(({name}) => name.search('test.js') == -1)
15
16
  .map(({name}) => `./web/${name}`);
16
17
 
@@ -18,20 +19,21 @@ const isDevelopment = (process.env.npm_lifecycle_event != 'prepare');
18
19
 
19
20
  const config = {
20
21
  entryPoints,
22
+ metafile: true, // for bundle analyser
21
23
  bundle: true,
22
24
  preserveSymlinks: true, // this allows us to use symlinks to ../shared
23
25
  minify: !isDevelopment,
24
26
  sourcemap: isDevelopment,
25
- target: ['es2022'],
26
27
  outdir: 'dist',
28
+ target: ['es2022'],
29
+ format: 'iife', // will be overwritten, see `formats` below
30
+ // splitting: true,
31
+ // external: ['react', 'react-dom'],
27
32
  define: {
28
33
  TR_PKG_VERSION: JSON.stringify(process.env.npm_package_version),
29
34
  TR_PKG_NAME: JSON.stringify(process.env.npm_package_name),
30
35
  TR_PKG_VERSION_NS: JSON.stringify(getPackageVersionNamespace()),
31
36
  },
32
- // plugins: [
33
- // svgrPlugin(),
34
- // ],
35
37
  loader: {
36
38
  '.svg': 'text',
37
39
  '.wasm': 'file',
@@ -41,24 +43,38 @@ const config = {
41
43
  name: 'rebuild-notify',
42
44
  setup(build) {
43
45
  build.onEnd(result => {
44
- console.log(new Date(),
46
+ console.log(new Date(), build.initialOptions.format,
45
47
  `build ended with ${result.errors.length} errors`);
46
48
 
47
49
  const dir = `/tmp/caps/${process.env.npm_package_name}`;
48
- isDevelopment && execSync(`mkdir -p ${dir} && cp -r package.json dist ${dir}`);
50
+ isDevelopment &&
51
+ execSync(`mkdir -p ${dir} && cp -r package.json dist ${dir}`);
52
+
53
+ const metaName = [process.env.npm_package_name.replace(/\//, '-'),
54
+ isDevelopment ? 'dev' : 'prod'
55
+ ].join('.');
56
+ fs.writeFileSync(`/tmp/${metaName}.meta.json`,
57
+ JSON.stringify(result.metafile));
49
58
  })
50
59
  },
51
60
  }],
52
61
  };
53
62
 
63
+
54
64
  const run = async () => {
55
- const ctx = await esbuild.context(config);
56
- if (isDevelopment) {
57
- await ctx.watch();
58
- } else {
59
- await ctx.rebuild();
60
- process.exit(0);
65
+
66
+ // define multiple config overwrites, for multiple outputs
67
+ const formats = [
68
+ { format: 'iife' },
69
+ { format: 'esm', outExtension: {'.js': '.esm.js'}}
70
+ ];
71
+
72
+ for (let overwrites of formats) {
73
+ const ctx = await esbuild.context({...config, ...overwrites});
74
+ isDevelopment ? ctx.watch() : await ctx.rebuild();
61
75
  }
76
+
77
+ !isDevelopment && process.exit(0);
62
78
  };
63
79
 
64
80
  run();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@transitive-sdk/utils-caps",
3
- "version": "0.1.3",
3
+ "version": "0.2.0",
4
4
  "description": "Utilities to build and run Transitive capabilities in dev",
5
5
  "homepage": "https://transitiverobotics.com",
6
6
  "repository": {