@cmmn/tools 1.9.4 → 1.9.6

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/bundle/bundle.js CHANGED
@@ -5,7 +5,7 @@ import fs from "fs";
5
5
  import path, {relative} from "path";
6
6
 
7
7
  export async function bundle(...options) {
8
- const configOptions = getConfigOptions({
8
+ const configOptions = await getConfigOptions({
9
9
  input: options.filter(x => !x.startsWith('-'))[0],
10
10
  project: options.includes('-b'),
11
11
  minify: options.includes('--prod'),
@@ -13,14 +13,16 @@ export async function bundle(...options) {
13
13
  stats: options.includes('--stats'),
14
14
  });
15
15
  const configs = configOptions.flatMap(x => new ConfigCreator(x).getConfig());
16
- const contexts = await Promise.all(configs.map(async x =>
17
- [x, await esbuild.context(x)]
18
- ));
16
+ const contexts = [];
17
+ for (let config of configs){
18
+ contexts.push([config, await esbuild.context(config)]);
19
+ }
19
20
 
20
21
  if (options.includes('--watch')) {
21
- for (let [name, context] of contexts) {
22
+ for (let [config, context] of contexts) {
22
23
  await context.watch();
23
24
  }
25
+ console.log('bundled. Continue watching...');
24
26
  }else {
25
27
  const logs = [];
26
28
  for (let [config, context] of contexts) {
@@ -117,7 +117,7 @@ export class ConfigCreator {
117
117
  getConfig() {
118
118
  if (this.options.external && typeof this.options.external === "string")
119
119
  this.options.external = [this.options.external]
120
- console.log(this.options.name, this.options);
120
+ // console.log(this.options.name, this.options);
121
121
  return this.modules.flatMap(format => this.platforms.map(platform => ({
122
122
  entryPoints: [
123
123
  { out: this.options.name, in: this.options.input }
@@ -138,7 +138,10 @@ export class ConfigCreator {
138
138
  },
139
139
  platform: platform,
140
140
  tsconfig: 'tsconfig.json',
141
- external: ["*.woff2", "*.woff", ...this.options.external],
141
+ external: [
142
+ "*.woff2", "*.woff",
143
+ ...(platform !== "node" && this.options.minify ? [] : this.options.external)
144
+ ],
142
145
  define: {
143
146
  'process.env.NODE_ENV': '"production"'
144
147
  },
@@ -1,6 +1,7 @@
1
1
  import fs from "fs";
2
2
  import path from "path";
3
3
  import fg from "fast-glob";
4
+ import { dependencyOrder } from "dependency-order";
4
5
 
5
6
  function getProjectConfig(rootDir, cmmn, options) {
6
7
  return {
@@ -10,21 +11,15 @@ function getProjectConfig(rootDir, cmmn, options) {
10
11
  };
11
12
  }
12
13
 
13
- function getPackageConfigs(rootDir, options, name = null) {
14
+ async function getPackageConfigs(rootDir, options, name = null, visited = []) {
14
15
  const pckPath = path.join(rootDir, 'package.json');
15
16
  if (!fs.existsSync(pckPath))
16
17
  return [];
17
18
  const results = [];
18
19
  const pkg = JSON.parse(fs.readFileSync(pckPath));
19
- if (pkg.workspaces){
20
- const dirs = pkg.workspaces.flatMap(pkg => fg.sync([pkg], {
21
- absolute: true,
22
- globstar: true,
23
- onlyDirectories: true,
24
- cwd: rootDir
25
- }));
26
- dirs.forEach(d => results.push(...getPackageConfigs(d, options, name)));
27
- }
20
+ const packageInfos = await dependencyOrder({
21
+ cwd: rootDir
22
+ });
28
23
  if (pkg.cmmn) {
29
24
  if (name) {
30
25
  results.push(getProjectConfig(rootDir, pkg.cmmn[name], {
@@ -42,32 +37,24 @@ function getPackageConfigs(rootDir, options, name = null) {
42
37
  }
43
38
  }
44
39
  }
40
+ for (let packageInfo of packageInfos) {
41
+ const root = packageInfo.packageMeta.directory;
42
+ if (visited.includes(root))
43
+ continue;
44
+ visited.push(root)
45
+ const configs = await getPackageConfigs(root, options, name, visited);
46
+ results.push(...configs);
47
+ }
45
48
  return results;
46
49
  }
47
50
 
48
- function getLernaSubPackages(lernaFile, options) {
49
- const config = JSON.parse(fs.readFileSync(lernaFile, 'utf8'));
50
- const packages = config.packages;
51
- const dirs = packages.flatMap(pkg => fg.sync([pkg], {
52
- absolute: true,
53
- globstar: true,
54
- onlyDirectories: true,
55
- cwd: path.dirname(lernaFile)
56
- }));
57
- return dirs.flatMap(dir => getPackageConfigs(dir, options));
58
- }
59
51
 
60
- export function getConfigOptions(options) {
52
+ export async function getConfigOptions(options) {
61
53
  if (!options.input || options.project) {
62
- const rootDir = process.cwd();
63
- const lernaPath = path.join(rootDir, 'lerna.json');
64
- if (fs.existsSync(lernaPath)) {
65
- return getLernaSubPackages(lernaPath, options);
66
- }
67
- return getPackageConfigs(process.cwd(), options);
54
+ return await getPackageConfigs(process.cwd(), options);
68
55
  }
69
56
  if (!options.input.includes('.') || !fs.existsSync(options.input)) {
70
- return getPackageConfigs(process.cwd(), options, options.input);
57
+ return await getPackageConfigs(process.cwd(), options, options.input);
71
58
  }
72
59
  return [options];
73
60
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.9.4",
3
+ "version": "1.9.6",
4
4
  "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
@@ -47,6 +47,7 @@
47
47
  "@types/jest": "27.x.x",
48
48
  "@types/sinon": "10.x.x",
49
49
  "@zerollup/ts-helpers": "1.7.18",
50
+ "dependency-order": "1.1.6",
50
51
  "esbuild": "0.19.5",
51
52
  "esbuild-plugin-less": "1.3.1",
52
53
  "esbuild-register": "3.5.0",
@@ -62,5 +63,5 @@
62
63
  },
63
64
  "author": "",
64
65
  "license": "ISC",
65
- "gitHead": "1602adb5285c0b8a7bd52d5a5d32860cdad4a434"
66
+ "gitHead": "2755b333808bf97f1d9454601c2a2c9a88e4a021"
66
67
  }
package/serve/serve.js CHANGED
@@ -5,8 +5,8 @@ import liveServer from "live-server";
5
5
  import {resolve, moduleResolve} from 'import-meta-resolve';
6
6
  import uri2path from "file-uri-to-path";
7
7
 
8
- export function serve(...options) {
9
- const configs = getConfigOptions({
8
+ export async function serve(...options) {
9
+ const configs = await getConfigOptions({
10
10
  project: options.includes('-b'),
11
11
  });
12
12
  configs.filter(x => x.port).forEach(async (x,i) => {