@cmmn/tools 1.3.0 → 1.4.2

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/bin.js CHANGED
@@ -1,4 +1,4 @@
1
- #!/usr/bin/env node
1
+ #!/usr/bin/env node
2
2
 
3
3
  import {bundle} from "./bundle/bundle.js";
4
4
  import {compile} from "./compile/compile.js";
package/bundle/bundle.js CHANGED
@@ -70,10 +70,14 @@ export async function bundle(...options) {
70
70
  });
71
71
  if (!options.includes('--watch')) {
72
72
  for (let config of configs) {
73
- console.log(`1. ${config.input} -> ${config.output.file}`);
73
+ for (let key in config.input){
74
+ // console.log(`1. ${key} (${config.input[key]})`);
75
+ }
74
76
  const build = await rollup(config);
75
- await build.write(config.output);
76
- console.log('SUCCESS');
77
+ for (let out of config.output){
78
+ console.log(`SUCCESS: ${out.dir} ${out.entryFileNames.replace('[name]', Object.keys(config.input)[0])}`);
79
+ await build.write(out);
80
+ }
77
81
  }
78
82
  return;
79
83
  }
@@ -88,10 +92,14 @@ export async function bundle(...options) {
88
92
  console.log('FINISH');
89
93
  break;
90
94
  case 'BUNDLE_START':
91
- console.log(`1. ${event.input} -> ${event.output}`);
95
+ for (let key in event.input){
96
+ console.log(`1. ${key} -> ${event.output}`);
97
+ }
92
98
  break;
93
99
  case 'BUNDLE_END':
94
- console.log(`1. ${event.input} -> ${event.output}, (${event.duration / 1000}s)`);
100
+ for (let key in event.input){
101
+ console.log(`1. ${key} -> ${event.output}, (${event.duration / 1000}s)`);
102
+ }
95
103
  break;
96
104
 
97
105
  case 'ERROR':
@@ -4,8 +4,9 @@ import {terser} from "rollup-plugin-terser"
4
4
  import {visualizer} from 'rollup-plugin-visualizer';
5
5
  import styles from "rollup-plugin-styles";
6
6
  import {string} from "rollup-plugin-string";
7
- import serve from 'rollup-plugin-serve'
8
- import livereload from 'rollup-plugin-livereload'
7
+ import serve from 'rollup-plugin-serve';
8
+ import builtins from 'rollup-plugin-node-builtins';
9
+ import livereload from 'rollup-plugin-livereload';
9
10
  import fs from "fs";
10
11
  import path from "path";
11
12
  import html from '@open-wc/rollup-plugin-html';
@@ -56,8 +57,8 @@ export class ConfigCreator {
56
57
  return path.join(this.root, this.options.outDir);
57
58
  }
58
59
 
59
- getOutputFileName(module, minify){
60
- switch (module){
60
+ getOutputFileName(module, minify) {
61
+ switch (module) {
61
62
  case "cjs":
62
63
  return `[name]${minify ? '.min' : ''}.cjs`;
63
64
  case "es":
@@ -79,7 +80,7 @@ export class ConfigCreator {
79
80
  dir: this.outDir,
80
81
  sourcemap: true,
81
82
  format: module,
82
- name: 'global',
83
+ name: this.options.global ?? 'global',
83
84
  }));
84
85
  }
85
86
 
@@ -123,14 +124,17 @@ export class ConfigCreator {
123
124
 
124
125
  get plugins() {
125
126
  const result = [
126
- // builtins(),
127
127
  nodeResolve({
128
128
  browser: this.options.browser,
129
129
  dedupe: this.options.dedupe || []
130
130
  }),
131
131
  commonjs({
132
132
  requireReturnsDefault: "namespace",
133
+ dynamicRequireTargets: [
134
+ 'node_modules/ulid/*.js'
135
+ ]
133
136
  }),
137
+ builtins(),
134
138
  styles({
135
139
  mode: "emit",
136
140
  }),
@@ -2,3 +2,18 @@ declare module "*.less"{
2
2
  const style: string;
3
3
  export default style;
4
4
  }
5
+
6
+ declare module "*.svg"{
7
+ const style: string;
8
+ export default style;
9
+ }
10
+
11
+ declare module "*.css"{
12
+ const style: string;
13
+ export default style;
14
+ }
15
+
16
+ declare module "*.html"{
17
+ const style: string;
18
+ export default style;
19
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@cmmn/tools",
3
- "version": "1.3.0",
4
- "description": "di, base extensions, useful functions",
3
+ "version": "1.4.2",
4
+ "description": "Compilation, bundling, code generator, testing.",
5
5
  "main": "dist/rollup.config.js",
6
6
  "type": "module",
7
7
  "publishConfig": {
@@ -11,23 +11,43 @@
11
11
  "bin": {
12
12
  "cmmn": "bin.js"
13
13
  },
14
+ "exports": {
15
+ "./test": "./test/index.js",
16
+ "./test/config": "./test/jest.config.js"
17
+ },
18
+ "typesVersions": {
19
+ "*": {
20
+ "test": [
21
+ "./test/index.d.ts"
22
+ ],
23
+ ".": [
24
+ "./compile/typings.d.ts"
25
+ ]
26
+ }
27
+ },
14
28
  "typings": "compile/typings.d.ts",
15
29
  "files": [
16
30
  "bin.js",
17
31
  "gen/*",
18
32
  "compile/*",
19
33
  "bundle/*",
20
- "plugins/*"
34
+ "plugins/*",
35
+ "test/*"
21
36
  ],
22
37
  "dependencies": {
38
+ "@jest/globals": "27.x.x",
23
39
  "@open-wc/rollup-plugin-html": "^1.2.5",
24
40
  "@rollup/plugin-alias": "3",
25
41
  "@rollup/plugin-commonjs": "^21",
26
42
  "@rollup/plugin-json": "4",
27
43
  "@rollup/plugin-node-resolve": "^13",
28
44
  "@rollup/plugin-typescript": "^8",
45
+ "@swc/jest": "0.2.17",
46
+ "@testdeck/jest": "0.2.0",
47
+ "@types/jest": "27.x.x",
29
48
  "@web/rollup-plugin-html": "^1.10.1",
30
49
  "fast-glob": "^3.2.11",
50
+ "jest": "27.x.x",
31
51
  "less": "^4",
32
52
  "rollup": "^2",
33
53
  "rollup-plugin-livereload": "^2.0.5",
@@ -38,11 +58,12 @@
38
58
  "rollup-plugin-styles": "^4",
39
59
  "rollup-plugin-terser": "^7",
40
60
  "rollup-plugin-visualizer": "^5.5.4",
61
+ "ts-jest": "27.x.x",
41
62
  "ttypescript": "1.5.13",
42
- "typescript": "4.4.3",
63
+ "typescript": "4.x.x",
43
64
  "typescript-transform-paths": "^3.3.1"
44
65
  },
45
66
  "author": "",
46
67
  "license": "ISC",
47
- "gitHead": "76478b70f43752f9bfe6cb96b4e540b1ff1e52e3"
68
+ "gitHead": "824d290afabaa3a44ccb98322cb1758825bd9efb"
48
69
  }
@@ -13,7 +13,7 @@ function visitExportNode(exportNode, sourceFile) {
13
13
  const sourceFileDir = path.dirname(sourceFile.path);
14
14
  const abs = path.resolve(sourceFileDir, file);
15
15
  if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
16
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFile.path));
16
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
17
17
  const relFile = path.relative(absSource, abs)
18
18
  return ts.updateExportDeclaration(exportNode, exportNode.decorators, exportNode.modifiers, exportNode.exportClause, ts.createStringLiteral(relFile), exportNode.typeOnly);
19
19
  }
@@ -33,7 +33,7 @@ function visitImportNode(importNode, sourceFile, options) {
33
33
  const sourceFileDir = path.dirname(sourceFile.path);
34
34
  const abs = path.resolve(sourceFileDir, file);
35
35
  if (/\.(less|css|scss|sass|svg|png|html)$/.test(file)) {
36
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFile.path));
36
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
37
37
  const relFile = path.relative(absSource, abs)
38
38
  return ts.updateImportDeclaration(importNode, importNode.decorators, importNode.modifiers, importNode.importClause, ts.createStringLiteral(relFile));
39
39
  }
@@ -55,7 +55,7 @@ function visitRequireNode(importNode, sourceFile) {
55
55
  if (/\.(less|css|scss|sass|svg|png|html)/.test(file)) {
56
56
  const sourceFileDir = path.dirname(sourceFile.path);
57
57
  const abs = path.join(sourceFileDir, file);
58
- const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFile.path));
58
+ const absSource = path.join(options.outDir, path.relative(options.baseUrl, sourceFileDir));
59
59
  const relFile = path.relative(absSource, abs)
60
60
  return ts.updateCall(importNode, importNode.expression, undefined, [ts.createStringLiteral(relFile)]);
61
61
  }
package/readme.md CHANGED
@@ -1,11 +1,31 @@
1
1
  ## Builder and bundler for your projects
2
2
 
3
3
  ### Use cases:
4
- `cmmn compile [target] [-b] [--watch]`
5
- > Runs typescript compiler
4
+ * `cmmn compile [target] [-b] [--watch]`
5
+ > Runs typescript compiler
6
6
 
7
- `cmmn bundle [target] [-b] [--watch] [--run] [--prod]`
8
- > Runs rollup bundler
7
+ * `cmmn bundle [target] [-b] [--watch] [--run] [--prod]`
8
+ > Runs rollup bundler
9
9
 
10
- `cmmn gen name directory [-n]`
11
- > Generates component with template at directory
10
+ * `cmmn gen name directory [-n]`
11
+ > Generates component with template at directory
12
+
13
+ * default `jest.config.js`:
14
+ ```typescript
15
+ import config from "@cmmn/tools/test/config";
16
+ export default config;
17
+ ```
18
+
19
+ * tests: `some.spec.ts`
20
+ ```typescript
21
+ import {suite, test, expect} from "@cmmn/tools/test";
22
+
23
+ @suite
24
+ export class SomeSpec {
25
+
26
+ @test
27
+ equalsTest() {
28
+ expect(1).toBe(2);
29
+ }
30
+ }
31
+ ```
@@ -0,0 +1,2 @@
1
+ export {suite, test, timeout,} from "@testdeck/jest";
2
+ export {expect,} from "@jest/globals";
package/test/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export {suite, test, timeout,} from "@testdeck/jest";
2
+ import * as globals from "@jest/globals";
3
+
4
+ const {expect} = globals;
5
+ export {expect};
@@ -0,0 +1,46 @@
1
+ import ts from "typescript";
2
+ import {pathsToModuleNameMapper} from "ts-jest";
3
+
4
+ const options = getTSConfig();
5
+
6
+ export default {
7
+ transform: {
8
+ '^.+\\.tsx?$': ['@swc/jest', {
9
+ jsc: {
10
+ parser: {
11
+ syntax: "typescript",
12
+ // tsx: true, // If you use react
13
+ dynamicImport: true,
14
+ decorators: true,
15
+ },
16
+ target: "es2021",
17
+ transform: {
18
+ decoratorMetadata: true,
19
+ },
20
+ paths: options.paths,
21
+ baseUrl: '.'
22
+ },
23
+ }],
24
+ },
25
+ roots: [process.cwd()],
26
+ moduleNameMapper: pathsToModuleNameMapper(options.paths ?? {}, {
27
+ prefix: '<rootDir>'
28
+ }),
29
+ extensionsToTreatAsEsm: ['.ts', '.tsx', '.jsx?'],
30
+ }
31
+
32
+
33
+ function getTSConfig() {
34
+ const configPath = ts.findConfigFile(process.cwd(), ts.sys.fileExists, 'tsconfig.json');
35
+ const readConfigFileResult = ts.readConfigFile(configPath, ts.sys.readFile);
36
+ if (readConfigFileResult.error) {
37
+ throw new Error(ts.formatDiagnostic(readConfigFileResult.error, formatHost));
38
+ }
39
+ const jsonConfig = readConfigFileResult.config;
40
+ const convertResult = ts.convertCompilerOptionsFromJson(jsonConfig.compilerOptions, './');
41
+ if (convertResult.errors && convertResult.errors.length > 0) {
42
+ throw new Error(ts.formatDiagnostics(convertResult.errors, formatHost));
43
+ }
44
+ const compilerOptions = convertResult.options;
45
+ return compilerOptions;
46
+ }