jitar 0.3.6 → 0.3.8
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 +6 -1
- package/LICENCE +23 -0
- package/dist/runtime/caching/ImportRewriter.js +30 -21
- package/package.json +5 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
# Changelog
|
|
3
3
|
|
|
4
|
-
## 0.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)
|
|
5
10
|
|
|
6
11
|
- Bump dependency for the latest version of jitar-reflection.
|
|
7
12
|
|
package/LICENCE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
|
|
2
|
+
(The MIT License)
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2023 Masking Technology B.V. <https://masking.tech>
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
7
|
+
a copy of this software and associated documentation files (the
|
|
8
|
+
'Software'), to deal in the Software without restriction, including
|
|
9
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
10
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
11
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
12
|
+
the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be
|
|
15
|
+
included in all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
18
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
19
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
20
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
21
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
22
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
23
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -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,45 @@ 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.#mustUseAs(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 #mustUseAs(dependency) {
|
|
44
|
+
return this.#doesImportAll(dependency)
|
|
45
|
+
|| this.#doesImportDefault(dependency);
|
|
46
|
+
}
|
|
47
|
+
static #doesImportAll(dependency) {
|
|
48
|
+
return dependency.members.length === 1
|
|
49
|
+
&& dependency.members[0].name === '*';
|
|
50
|
+
}
|
|
51
|
+
static #doesImportDefault(dependency) {
|
|
52
|
+
return dependency.members.length === 1
|
|
53
|
+
&& dependency.members[0].name === 'default';
|
|
45
54
|
}
|
|
46
55
|
static #insertGetDependency(module) {
|
|
47
56
|
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.8",
|
|
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,7 +21,7 @@
|
|
|
21
21
|
"release": "npm run clean && npm run build && npm publish"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"jitar-reflection": "^0.3.
|
|
24
|
+
"jitar-reflection": "^0.3.7"
|
|
25
25
|
},
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=18.7"
|
|
@@ -43,5 +43,6 @@
|
|
|
43
43
|
"monolith",
|
|
44
44
|
"full stack",
|
|
45
45
|
"web applications"
|
|
46
|
-
]
|
|
47
|
-
|
|
46
|
+
],
|
|
47
|
+
"gitHead": "8eafe79ce9317964f843301bc2fbf6278a4fb88f"
|
|
48
|
+
}
|