jitar 0.3.4 → 0.3.7
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 +9 -0
- package/dist/runtime/caching/ImportRewriter.js +22 -21
- package/package.json +4 -12
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
|
|
2
2
|
# Changelog
|
|
3
3
|
|
|
4
|
+
## 0.3.7 (February 26, 2023)
|
|
5
|
+
|
|
6
|
+
Fixes:
|
|
7
|
+
- \[[`b9c9db3`](https://github.com/MaskingTechnology/jitar/commit/b9c9db3)] Fixed importing commonJS modules [petermasking](https://github.com/MaskingTechnology/jitar/pull/182)
|
|
8
|
+
|
|
9
|
+
## 0.3.6 (February 26, 2023)
|
|
10
|
+
|
|
11
|
+
- Bump dependency for the latest version of jitar-reflection.
|
|
12
|
+
|
|
4
13
|
## 0.3.4 (February 23, 2023)
|
|
5
14
|
|
|
6
15
|
New features:
|
|
@@ -1,14 +1,8 @@
|
|
|
1
|
+
import { Reflector } from 'jitar-reflection';
|
|
1
2
|
import * as Keywords from './definitions/Keywords.js';
|
|
2
3
|
const IMPORT_PATTERN = /import(?:["'\s]*([\w*{}\n, ]+)from\s*)?["'\s]*([@\w/_-]+)["'\s].*/g;
|
|
3
4
|
const NON_SYSTEM_INDICATORS = ['.', '/', 'http:', 'https:'];
|
|
4
|
-
|
|
5
|
-
items;
|
|
6
|
-
from;
|
|
7
|
-
constructor(items, from) {
|
|
8
|
-
this.items = items;
|
|
9
|
-
this.from = from;
|
|
10
|
-
}
|
|
11
|
-
}
|
|
5
|
+
const reflector = new Reflector();
|
|
12
6
|
export default class ImportRewriter {
|
|
13
7
|
static rewrite(content) {
|
|
14
8
|
const replacer = (statement) => this.#replaceImport(statement);
|
|
@@ -18,30 +12,37 @@ export default class ImportRewriter {
|
|
|
18
12
|
: newContent;
|
|
19
13
|
}
|
|
20
14
|
static #replaceImport(statement) {
|
|
21
|
-
const dependency =
|
|
15
|
+
const dependency = reflector.parseImport(statement);
|
|
22
16
|
return this.#isSystemDependency(dependency)
|
|
23
17
|
? this.#rewriteImport(dependency)
|
|
24
18
|
: statement;
|
|
25
19
|
}
|
|
26
|
-
static #parseImport(statement) {
|
|
27
|
-
const hasSemicolon = statement.endsWith(';');
|
|
28
|
-
const fromIndex = statement.indexOf('from');
|
|
29
|
-
const endIndex = statement.length - (hasSemicolon ? 1 : 0);
|
|
30
|
-
const items = statement.substring(6, fromIndex).trim();
|
|
31
|
-
const from = statement.substring(fromIndex + 4, endIndex).trim().slice(1, -1);
|
|
32
|
-
return new Dependency(items, from);
|
|
33
|
-
}
|
|
34
20
|
static #isSystemDependency(dependency) {
|
|
35
|
-
return NON_SYSTEM_INDICATORS.some(indicator => dependency.from.startsWith(indicator)) === false;
|
|
21
|
+
return NON_SYSTEM_INDICATORS.some(indicator => dependency.from.startsWith(indicator, 1)) === false;
|
|
36
22
|
}
|
|
37
23
|
static #isJitarDependency(dependency) {
|
|
38
|
-
return dependency.from
|
|
24
|
+
return dependency.from.includes(Keywords.JITAR);
|
|
39
25
|
}
|
|
40
26
|
static #rewriteImport(dependency) {
|
|
27
|
+
if (dependency.members.length === 0) {
|
|
28
|
+
return `await getDependency(${dependency.from});`;
|
|
29
|
+
}
|
|
30
|
+
const members = this.#rewriteImportMembers(dependency);
|
|
41
31
|
if (this.#isJitarDependency(dependency)) {
|
|
42
|
-
return `import ${
|
|
32
|
+
return `import ${members} from "/jitar/hooks.js";`;
|
|
43
33
|
}
|
|
44
|
-
return `const ${
|
|
34
|
+
return `const ${members} = await getDependency(${dependency.from});`;
|
|
35
|
+
}
|
|
36
|
+
static #rewriteImportMembers(dependency) {
|
|
37
|
+
if (this.#doesImportAll(dependency)) {
|
|
38
|
+
return dependency.members[0].as;
|
|
39
|
+
}
|
|
40
|
+
const members = dependency.members.map(member => member.name !== member.as ? `${member.name}: ${member.as}` : member.name);
|
|
41
|
+
return `{ ${members.join(', ')} }`;
|
|
42
|
+
}
|
|
43
|
+
static #doesImportAll(dependency) {
|
|
44
|
+
return dependency.members.length === 1
|
|
45
|
+
&& dependency.members[0].name === '*';
|
|
45
46
|
}
|
|
46
47
|
static #insertGetDependency(module) {
|
|
47
48
|
return `import { getDependency } from "/jitar/hooks.js";\n${module}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jitar",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.7",
|
|
4
4
|
"description": "Distributed runtime for JavaScript and TypeScript to chop monolithic applications into micros.",
|
|
5
5
|
"author": "Masking Technology <info@masking.tech> (https://jitar.dev)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -21,14 +21,7 @@
|
|
|
21
21
|
"release": "npm run clean && npm run build && npm publish"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"jitar-reflection": "^0.3.
|
|
25
|
-
},
|
|
26
|
-
"devDependencies": {
|
|
27
|
-
"@typescript-eslint/eslint-plugin": "^5.52.0",
|
|
28
|
-
"@typescript-eslint/parser": "^5.52.0",
|
|
29
|
-
"@vitest/coverage-c8": "^0.28.5",
|
|
30
|
-
"eslint": "^8.34.0",
|
|
31
|
-
"vitest": "^0.28.5"
|
|
24
|
+
"jitar-reflection": "^0.3.7"
|
|
32
25
|
},
|
|
33
26
|
"engines": {
|
|
34
27
|
"node": ">=18.7"
|
|
@@ -50,6 +43,5 @@
|
|
|
50
43
|
"monolith",
|
|
51
44
|
"full stack",
|
|
52
45
|
"web applications"
|
|
53
|
-
]
|
|
54
|
-
|
|
55
|
-
}
|
|
46
|
+
]
|
|
47
|
+
}
|