@cmmn/tools 1.9.12 → 1.9.13
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/esbuild.config.js +2 -1
- package/package.json +5 -8
- package/readme.md +1 -1
- package/test/index.d.ts +17 -2
- package/test/index.js +10 -5
- package/test/jest.config.js +1 -1
- package/test/pathsToModuleNameMapper.js +46 -0
package/bundle/esbuild.config.js
CHANGED
|
@@ -135,7 +135,8 @@ export class ConfigCreator {
|
|
|
135
135
|
es: 'esm'
|
|
136
136
|
})[format] ?? format,
|
|
137
137
|
outExtension: {
|
|
138
|
-
'.js': this.getOutExtension(format, platform)
|
|
138
|
+
'.js': this.getOutExtension(format, platform),
|
|
139
|
+
'.css': this.options.minify ? '.min.css' : '.css'
|
|
139
140
|
},
|
|
140
141
|
footer:{
|
|
141
142
|
js: `//# sourceMappingURL=./${this.options.name+this.getOutExtension(format, platform)}.map`
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cmmn/tools",
|
|
3
|
-
"version": "1.9.
|
|
3
|
+
"version": "1.9.13",
|
|
4
4
|
"description": "Compilation, bundling, code generator, testing.",
|
|
5
5
|
"main": "dist/rollup.config.js",
|
|
6
6
|
"type": "module",
|
|
@@ -41,13 +41,11 @@
|
|
|
41
41
|
"helpers/*"
|
|
42
42
|
],
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@jest/globals": "27.x.x",
|
|
45
|
-
"@swc/jest": "0.2.17",
|
|
46
44
|
"@testdeck/jest": "0.2.0",
|
|
47
|
-
"@types/
|
|
45
|
+
"@types/node": "20.x.x",
|
|
48
46
|
"@types/sinon": "10.x.x",
|
|
49
47
|
"@zerollup/ts-helpers": "1.7.18",
|
|
50
|
-
"
|
|
48
|
+
"earl": "^1.1.0",
|
|
51
49
|
"esbuild": "0.19.5",
|
|
52
50
|
"esbuild-plugin-less": "1.3.1",
|
|
53
51
|
"esbuild-register": "3.5.0",
|
|
@@ -55,11 +53,10 @@
|
|
|
55
53
|
"fast-glob": "^3.2.11",
|
|
56
54
|
"file-uri-to-path": "2.x.x",
|
|
57
55
|
"import-meta-resolve": "2",
|
|
58
|
-
"
|
|
56
|
+
"jasmine-expect": "5.0.0",
|
|
59
57
|
"less": "^4",
|
|
60
58
|
"live-server": "1.2.2",
|
|
61
|
-
"sinon": "
|
|
62
|
-
"ts-jest": "29.x.x"
|
|
59
|
+
"sinon": "17.0.1"
|
|
63
60
|
},
|
|
64
61
|
"author": "",
|
|
65
62
|
"license": "ISC",
|
package/readme.md
CHANGED
package/test/index.d.ts
CHANGED
|
@@ -1,3 +1,18 @@
|
|
|
1
1
|
export {suite, test, timeout,} from "@testdeck/jest";
|
|
2
|
-
export {expect
|
|
3
|
-
|
|
2
|
+
export {expect} from "earl";
|
|
3
|
+
import * as sinonModule from "sinon";
|
|
4
|
+
|
|
5
|
+
export type AssertionExt = Assertion & {
|
|
6
|
+
toEqual: Assertion["eql"]
|
|
7
|
+
}
|
|
8
|
+
export const sinon = sinonModule;
|
|
9
|
+
|
|
10
|
+
declare module 'earl' {
|
|
11
|
+
interface Validators<T> {
|
|
12
|
+
// Note that `this: Validators<number>` ensures that
|
|
13
|
+
// the validator is only callable for numbers.
|
|
14
|
+
toBeInstanceOf<V>(this: Validators<T>, type: V): T extends V ? true : false;
|
|
15
|
+
toBe: Validators<T>["toEqual"];
|
|
16
|
+
toHaveProperty<TProp, TValue>(this: Validators<T>, prop: TProp, value: TValue): T extends Record<TProp, TValue> ? true: false;
|
|
17
|
+
}
|
|
18
|
+
}
|
package/test/index.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
|
+
import * as test from "node:test";
|
|
2
|
+
Object.assign(globalThis, test);
|
|
1
3
|
export {suite, test, timeout,} from "@testdeck/jest";
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
import { expect as expectBase, registerValidator, isEqual} from "earl";
|
|
5
|
+
import assert from "node:assert";
|
|
6
|
+
// import * as globals from "@jest/globals";
|
|
7
|
+
export * as sinon from "sinon";
|
|
8
|
+
registerValidator("toBe", isEqual)
|
|
9
|
+
registerValidator("toBeInstanceOf", type => value => value instanceof type)
|
|
10
|
+
registerValidator("toHaveProperty", (prop, value) => obj => isEqual(obj[prop], value))
|
|
11
|
+
export const expect = expectBase;
|
package/test/jest.config.js
CHANGED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
// we don't need to escape all chars, so commented out is the real one
|
|
2
|
+
// const escapeRegex = (str: string) => str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
|
|
3
|
+
const escapeRegex = (str) => str.replace(/[-\\^$*+?.()|[\]{}]/g, '\\$&')
|
|
4
|
+
|
|
5
|
+
export const pathsToModuleNameMapper = (mapping, { prefix = '', useESM = false }= {}) => {
|
|
6
|
+
const jestMap = {}
|
|
7
|
+
for (const fromPath of Object.keys(mapping)) {
|
|
8
|
+
const toPaths = mapping[fromPath]
|
|
9
|
+
// check that we have only one target path
|
|
10
|
+
if (toPaths.length === 0) {
|
|
11
|
+
continue
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// split with '*'
|
|
15
|
+
const segments = fromPath.split(/\*/g)
|
|
16
|
+
if (segments.length === 1) {
|
|
17
|
+
const paths = toPaths.map((target) => {
|
|
18
|
+
const enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? `${prefix}/` : prefix
|
|
19
|
+
|
|
20
|
+
return `${enrichedPrefix}${target}`
|
|
21
|
+
})
|
|
22
|
+
const cjsPattern = `^${escapeRegex(fromPath)}$`
|
|
23
|
+
jestMap[cjsPattern] = paths.length === 1 ? paths[0] : paths
|
|
24
|
+
} else if (segments.length === 2) {
|
|
25
|
+
const paths = toPaths.map((target) => {
|
|
26
|
+
const enrichedTarget =
|
|
27
|
+
target.startsWith('./') && prefix !== '' ? target.substring(target.indexOf('/') + 1) : target
|
|
28
|
+
const enrichedPrefix = prefix !== '' && !prefix.endsWith('/') ? `${prefix}/` : prefix
|
|
29
|
+
|
|
30
|
+
return `${enrichedPrefix}${enrichedTarget.replace(/\*/g, '$1')}`
|
|
31
|
+
})
|
|
32
|
+
if (useESM) {
|
|
33
|
+
const esmPattern = `^${escapeRegex(segments[0])}(.*)${escapeRegex(segments[1])}\\.js$`
|
|
34
|
+
jestMap[esmPattern] = paths.length === 1 ? paths[0] : paths
|
|
35
|
+
}
|
|
36
|
+
const cjsPattern = `^${escapeRegex(segments[0])}(.*)${escapeRegex(segments[1])}$`
|
|
37
|
+
jestMap[cjsPattern] = paths.length === 1 ? paths[0] : paths
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
if (useESM) {
|
|
42
|
+
jestMap['^(\\.{1,2}/.*)\\.js$'] = '$1'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return jestMap
|
|
46
|
+
}
|