unplugin-atscript 0.1.88 → 0.1.90
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/README.md +12 -0
- package/dist/esbuild.cjs +50 -29
- package/dist/esbuild.d.ts +14 -0
- package/dist/esbuild.mjs +30 -13
- package/dist/farm.cjs +50 -29
- package/dist/farm.d.ts +14 -0
- package/dist/farm.mjs +30 -13
- package/dist/index.cjs +57 -37
- package/dist/index.d.ts +14 -0
- package/dist/index.mjs +33 -17
- package/dist/rolldown.cjs +50 -29
- package/dist/rolldown.d.ts +14 -0
- package/dist/rolldown.mjs +30 -13
- package/dist/rollup.cjs +50 -29
- package/dist/rollup.d.ts +14 -0
- package/dist/rollup.mjs +30 -13
- package/dist/rspack.cjs +50 -29
- package/dist/rspack.d.ts +14 -0
- package/dist/rspack.mjs +30 -13
- package/dist/vite.cjs +50 -29
- package/dist/vite.d.ts +14 -0
- package/dist/vite.mjs +30 -13
- package/dist/webpack.cjs +50 -29
- package/dist/webpack.d.ts +14 -0
- package/dist/webpack.mjs +30 -13
- package/package.json +3 -3
package/dist/webpack.mjs
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
import { createWebpackPlugin } from "unplugin";
|
|
2
2
|
import { readFile } from "fs/promises";
|
|
3
|
+
import { createRequire } from "module";
|
|
3
4
|
import path from "path";
|
|
4
5
|
import { AtscriptRepo, isAnnotate, loadConfig, resolveConfigFile } from "@atscript/core";
|
|
5
6
|
import { tsPlugin } from "@atscript/typescript";
|
|
6
7
|
|
|
7
8
|
//#region packages/unplugin/src/index.ts
|
|
8
9
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
10
|
+
const RUNTIME_ENTRY = "@atscript/typescript/utils";
|
|
11
|
+
function isResolvableFrom(specifier, from) {
|
|
12
|
+
try {
|
|
13
|
+
createRequire(path.join(from, "package.json")).resolve(specifier);
|
|
14
|
+
return true;
|
|
15
|
+
} catch {
|
|
16
|
+
return false;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
9
19
|
const unpluginFactory = (opts) => {
|
|
10
|
-
const
|
|
20
|
+
const explicitRoot = opts?.root ? path.resolve(opts.root) : void 0;
|
|
21
|
+
let detectedRoot;
|
|
22
|
+
const getRoot = () => explicitRoot ?? detectedRoot ?? process.cwd();
|
|
11
23
|
const strict = opts?.strict ?? true;
|
|
12
24
|
let repo;
|
|
13
25
|
let configPromise;
|
|
14
26
|
const getConfig = () => configPromise ?? (configPromise = (async () => {
|
|
15
|
-
const p = await resolveConfigFile(
|
|
27
|
+
const p = await resolveConfigFile(getRoot());
|
|
16
28
|
return p ? loadConfig(p) : {};
|
|
17
29
|
})());
|
|
18
30
|
return {
|
|
19
31
|
name: "unplugin-atscript",
|
|
32
|
+
vite: {
|
|
33
|
+
config(userConfig) {
|
|
34
|
+
const root = path.resolve(explicitRoot ?? userConfig.root ?? process.cwd());
|
|
35
|
+
return (userConfig.optimizeDeps?.include?.includes(RUNTIME_ENTRY) ?? false) || !isResolvableFrom(RUNTIME_ENTRY, root) ? void 0 : { optimizeDeps: { include: [RUNTIME_ENTRY] } };
|
|
36
|
+
},
|
|
37
|
+
configResolved(config) {
|
|
38
|
+
detectedRoot = config.root;
|
|
39
|
+
}
|
|
40
|
+
},
|
|
20
41
|
resolveId(id, importer) {
|
|
21
42
|
if (importer && id.endsWith(".as")) {
|
|
22
43
|
if (!id.startsWith(".") && !id.startsWith("/")) return null;
|
|
@@ -27,12 +48,12 @@ const unpluginFactory = (opts) => {
|
|
|
27
48
|
},
|
|
28
49
|
async load(id) {
|
|
29
50
|
const isDts = id.endsWith(".as.d.ts");
|
|
30
|
-
const sourceId = isDts ? id.slice(0, -
|
|
51
|
+
const sourceId = isDts ? id.slice(0, -5) : id;
|
|
31
52
|
if (sourceId.endsWith(".as")) {
|
|
32
53
|
if (!repo) {
|
|
33
54
|
const config = await getConfig();
|
|
34
55
|
if (!config.plugins) config.plugins = [tsPlugin()];
|
|
35
|
-
repo = new AtscriptRepo(
|
|
56
|
+
repo = new AtscriptRepo(getRoot(), config);
|
|
36
57
|
}
|
|
37
58
|
const code = (await readFile(sourceId, "utf8")).toString();
|
|
38
59
|
const doc = await repo.openDocument(`file://${sourceId}`, code);
|
|
@@ -44,21 +65,17 @@ const unpluginFactory = (opts) => {
|
|
|
44
65
|
if (strict && !error) error = m.message;
|
|
45
66
|
} else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
|
|
46
67
|
if (error) throw new Error(error);
|
|
47
|
-
if (isDts) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
code: content,
|
|
52
|
-
map: null
|
|
53
|
-
};
|
|
54
|
-
}
|
|
68
|
+
if (isDts) return {
|
|
69
|
+
code: ((await doc.render("dts"))?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, ""),
|
|
70
|
+
map: null
|
|
71
|
+
};
|
|
55
72
|
const out = await doc.render("js");
|
|
56
73
|
const hasMutatingAnnotates = doc.nodes.some((n) => isAnnotate(n) && n.isMutating);
|
|
57
74
|
return {
|
|
58
75
|
code: out?.[0]?.content || "",
|
|
59
76
|
moduleType: "js",
|
|
60
77
|
map: null,
|
|
61
|
-
moduleSideEffects: hasMutatingAnnotates ?
|
|
78
|
+
moduleSideEffects: hasMutatingAnnotates ? void 0 : false
|
|
62
79
|
};
|
|
63
80
|
}
|
|
64
81
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-atscript",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.90",
|
|
4
4
|
"description": "Atscript: Configuration and build plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"annotations",
|
|
@@ -82,8 +82,8 @@
|
|
|
82
82
|
"vitest": "3.2.7"
|
|
83
83
|
},
|
|
84
84
|
"peerDependencies": {
|
|
85
|
-
"@atscript/core": "^0.1.
|
|
86
|
-
"@atscript/typescript": "^0.1.
|
|
85
|
+
"@atscript/core": "^0.1.90",
|
|
86
|
+
"@atscript/typescript": "^0.1.90"
|
|
87
87
|
},
|
|
88
88
|
"build": [
|
|
89
89
|
{},
|