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/index.d.ts
CHANGED
|
@@ -7,6 +7,20 @@ interface atscriptPluginOptions {
|
|
|
7
7
|
* @default true
|
|
8
8
|
*/
|
|
9
9
|
strict?: boolean;
|
|
10
|
+
/**
|
|
11
|
+
* The directory `atscript.config.*` is discovered from and `.as` files are
|
|
12
|
+
* resolved against. Absolute, or relative to `process.cwd()`.
|
|
13
|
+
*
|
|
14
|
+
* Defaults to the bundler's root (Vite: `config.root`, picked up automatically
|
|
15
|
+
* in `configResolved`) or `process.cwd()`.
|
|
16
|
+
*
|
|
17
|
+
* Vite picks the root up automatically; other bundlers need `root` when the
|
|
18
|
+
* working directory is not the project root (monorepo `pnpm -C`, editor-launched
|
|
19
|
+
* builds, a root that sits next to — not above — the config). Without it the
|
|
20
|
+
* config is discovered from the wrong directory and valid annotations from
|
|
21
|
+
* config-provided plugins (`@db.*`, `@ui.*`, …) are reported as unknown.
|
|
22
|
+
*/
|
|
23
|
+
root?: string;
|
|
10
24
|
}
|
|
11
25
|
declare const unpluginFactory: UnpluginFactory<atscriptPluginOptions | undefined>;
|
|
12
26
|
declare const unplugin: _unplugin.UnpluginInstance<atscriptPluginOptions | undefined, boolean>;
|
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { readFile } from "fs/promises";
|
|
2
|
+
import { createRequire } from "module";
|
|
2
3
|
import path from "path";
|
|
3
4
|
import { AtscriptRepo, isAnnotate, loadConfig, resolveConfigFile } from "@atscript/core";
|
|
4
5
|
import { tsPlugin } from "@atscript/typescript";
|
|
@@ -6,17 +7,37 @@ import { createUnplugin } from "unplugin";
|
|
|
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,29 +65,24 @@ 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
|
}
|
|
65
82
|
};
|
|
66
83
|
};
|
|
67
|
-
const unplugin = /*
|
|
68
|
-
const asPlugin = unplugin;
|
|
69
|
-
var src_default = unplugin;
|
|
84
|
+
const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
|
|
85
|
+
/** @deprecated Use `import atscript from 'unplugin-atscript/vite'` (or /rollup, /webpack, etc.) instead */ const asPlugin = unplugin;
|
|
70
86
|
|
|
71
87
|
//#endregion
|
|
72
|
-
export { asPlugin,
|
|
88
|
+
export { asPlugin, unplugin as default, unplugin, unpluginFactory };
|
package/dist/rolldown.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region rolldown:runtime
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
8
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
20
|
return to;
|
|
18
21
|
};
|
|
@@ -22,25 +25,47 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
25
|
}) : target, mod));
|
|
23
26
|
|
|
24
27
|
//#endregion
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let unplugin = require("unplugin");
|
|
29
|
+
let fs_promises = require("fs/promises");
|
|
30
|
+
let module$1 = require("module");
|
|
31
|
+
let path = require("path");
|
|
32
|
+
path = __toESM(path);
|
|
33
|
+
let _atscript_core = require("@atscript/core");
|
|
34
|
+
let _atscript_typescript = require("@atscript/typescript");
|
|
30
35
|
|
|
31
36
|
//#region packages/unplugin/src/index.ts
|
|
32
37
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
38
|
+
const RUNTIME_ENTRY = "@atscript/typescript/utils";
|
|
39
|
+
function isResolvableFrom(specifier, from) {
|
|
40
|
+
try {
|
|
41
|
+
(0, module$1.createRequire)(path.default.join(from, "package.json")).resolve(specifier);
|
|
42
|
+
return true;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
33
47
|
const unpluginFactory = (opts) => {
|
|
34
|
-
const
|
|
48
|
+
const explicitRoot = opts?.root ? path.default.resolve(opts.root) : void 0;
|
|
49
|
+
let detectedRoot;
|
|
50
|
+
const getRoot = () => explicitRoot ?? detectedRoot ?? process.cwd();
|
|
35
51
|
const strict = opts?.strict ?? true;
|
|
36
52
|
let repo;
|
|
37
53
|
let configPromise;
|
|
38
54
|
const getConfig = () => configPromise ?? (configPromise = (async () => {
|
|
39
|
-
const p = await (0,
|
|
40
|
-
return p ? (0,
|
|
55
|
+
const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
|
|
56
|
+
return p ? (0, _atscript_core.loadConfig)(p) : {};
|
|
41
57
|
})());
|
|
42
58
|
return {
|
|
43
59
|
name: "unplugin-atscript",
|
|
60
|
+
vite: {
|
|
61
|
+
config(userConfig) {
|
|
62
|
+
const root = path.default.resolve(explicitRoot ?? userConfig.root ?? process.cwd());
|
|
63
|
+
return (userConfig.optimizeDeps?.include?.includes(RUNTIME_ENTRY) ?? false) || !isResolvableFrom(RUNTIME_ENTRY, root) ? void 0 : { optimizeDeps: { include: [RUNTIME_ENTRY] } };
|
|
64
|
+
},
|
|
65
|
+
configResolved(config) {
|
|
66
|
+
detectedRoot = config.root;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
44
69
|
resolveId(id, importer) {
|
|
45
70
|
if (importer && id.endsWith(".as")) {
|
|
46
71
|
if (!id.startsWith(".") && !id.startsWith("/")) return null;
|
|
@@ -51,12 +76,12 @@ const unpluginFactory = (opts) => {
|
|
|
51
76
|
},
|
|
52
77
|
async load(id) {
|
|
53
78
|
const isDts = id.endsWith(".as.d.ts");
|
|
54
|
-
const sourceId = isDts ? id.slice(0, -
|
|
79
|
+
const sourceId = isDts ? id.slice(0, -5) : id;
|
|
55
80
|
if (sourceId.endsWith(".as")) {
|
|
56
81
|
if (!repo) {
|
|
57
82
|
const config = await getConfig();
|
|
58
|
-
if (!config.plugins) config.plugins = [(0,
|
|
59
|
-
repo = new
|
|
83
|
+
if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
|
|
84
|
+
repo = new _atscript_core.AtscriptRepo(getRoot(), config);
|
|
60
85
|
}
|
|
61
86
|
const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
|
|
62
87
|
const doc = await repo.openDocument(`file://${sourceId}`, code);
|
|
@@ -68,21 +93,17 @@ const unpluginFactory = (opts) => {
|
|
|
68
93
|
if (strict && !error) error = m.message;
|
|
69
94
|
} else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
|
|
70
95
|
if (error) throw new Error(error);
|
|
71
|
-
if (isDts) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
code: content,
|
|
76
|
-
map: null
|
|
77
|
-
};
|
|
78
|
-
}
|
|
96
|
+
if (isDts) return {
|
|
97
|
+
code: ((await doc.render("dts"))?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, ""),
|
|
98
|
+
map: null
|
|
99
|
+
};
|
|
79
100
|
const out = await doc.render("js");
|
|
80
|
-
const hasMutatingAnnotates = doc.nodes.some((n) => (0,
|
|
101
|
+
const hasMutatingAnnotates = doc.nodes.some((n) => (0, _atscript_core.isAnnotate)(n) && n.isMutating);
|
|
81
102
|
return {
|
|
82
103
|
code: out?.[0]?.content || "",
|
|
83
104
|
moduleType: "js",
|
|
84
105
|
map: null,
|
|
85
|
-
moduleSideEffects: hasMutatingAnnotates ?
|
|
106
|
+
moduleSideEffects: hasMutatingAnnotates ? void 0 : false
|
|
86
107
|
};
|
|
87
108
|
}
|
|
88
109
|
}
|
package/dist/rolldown.d.ts
CHANGED
|
@@ -6,6 +6,20 @@ interface atscriptPluginOptions {
|
|
|
6
6
|
* @default true
|
|
7
7
|
*/
|
|
8
8
|
strict?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The directory `atscript.config.*` is discovered from and `.as` files are
|
|
11
|
+
* resolved against. Absolute, or relative to `process.cwd()`.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to the bundler's root (Vite: `config.root`, picked up automatically
|
|
14
|
+
* in `configResolved`) or `process.cwd()`.
|
|
15
|
+
*
|
|
16
|
+
* Vite picks the root up automatically; other bundlers need `root` when the
|
|
17
|
+
* working directory is not the project root (monorepo `pnpm -C`, editor-launched
|
|
18
|
+
* builds, a root that sits next to — not above — the config). Without it the
|
|
19
|
+
* config is discovered from the wrong directory and valid annotations from
|
|
20
|
+
* config-provided plugins (`@db.*`, `@ui.*`, …) are reported as unknown.
|
|
21
|
+
*/
|
|
22
|
+
root?: string;
|
|
9
23
|
}
|
|
10
24
|
|
|
11
25
|
declare const _default: (options?: atscriptPluginOptions | undefined) => rolldown.Plugin<any> | rolldown.Plugin<any>[];
|
package/dist/rolldown.mjs
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
import { createRolldownPlugin } 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/dist/rollup.cjs
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
//#region rolldown:runtime
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
3
2
|
var __create = Object.create;
|
|
4
3
|
var __defProp = Object.defineProperty;
|
|
5
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -7,12 +6,16 @@ var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
|
7
6
|
var __getProtoOf = Object.getPrototypeOf;
|
|
8
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
8
|
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function")
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
10
|
+
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
13
|
+
__defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
16
19
|
}
|
|
17
20
|
return to;
|
|
18
21
|
};
|
|
@@ -22,25 +25,47 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
22
25
|
}) : target, mod));
|
|
23
26
|
|
|
24
27
|
//#endregion
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
let unplugin = require("unplugin");
|
|
29
|
+
let fs_promises = require("fs/promises");
|
|
30
|
+
let module$1 = require("module");
|
|
31
|
+
let path = require("path");
|
|
32
|
+
path = __toESM(path);
|
|
33
|
+
let _atscript_core = require("@atscript/core");
|
|
34
|
+
let _atscript_typescript = require("@atscript/typescript");
|
|
30
35
|
|
|
31
36
|
//#region packages/unplugin/src/index.ts
|
|
32
37
|
const RE_DTS = /\.d\.[cm]?ts$/;
|
|
38
|
+
const RUNTIME_ENTRY = "@atscript/typescript/utils";
|
|
39
|
+
function isResolvableFrom(specifier, from) {
|
|
40
|
+
try {
|
|
41
|
+
(0, module$1.createRequire)(path.default.join(from, "package.json")).resolve(specifier);
|
|
42
|
+
return true;
|
|
43
|
+
} catch {
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
33
47
|
const unpluginFactory = (opts) => {
|
|
34
|
-
const
|
|
48
|
+
const explicitRoot = opts?.root ? path.default.resolve(opts.root) : void 0;
|
|
49
|
+
let detectedRoot;
|
|
50
|
+
const getRoot = () => explicitRoot ?? detectedRoot ?? process.cwd();
|
|
35
51
|
const strict = opts?.strict ?? true;
|
|
36
52
|
let repo;
|
|
37
53
|
let configPromise;
|
|
38
54
|
const getConfig = () => configPromise ?? (configPromise = (async () => {
|
|
39
|
-
const p = await (0,
|
|
40
|
-
return p ? (0,
|
|
55
|
+
const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
|
|
56
|
+
return p ? (0, _atscript_core.loadConfig)(p) : {};
|
|
41
57
|
})());
|
|
42
58
|
return {
|
|
43
59
|
name: "unplugin-atscript",
|
|
60
|
+
vite: {
|
|
61
|
+
config(userConfig) {
|
|
62
|
+
const root = path.default.resolve(explicitRoot ?? userConfig.root ?? process.cwd());
|
|
63
|
+
return (userConfig.optimizeDeps?.include?.includes(RUNTIME_ENTRY) ?? false) || !isResolvableFrom(RUNTIME_ENTRY, root) ? void 0 : { optimizeDeps: { include: [RUNTIME_ENTRY] } };
|
|
64
|
+
},
|
|
65
|
+
configResolved(config) {
|
|
66
|
+
detectedRoot = config.root;
|
|
67
|
+
}
|
|
68
|
+
},
|
|
44
69
|
resolveId(id, importer) {
|
|
45
70
|
if (importer && id.endsWith(".as")) {
|
|
46
71
|
if (!id.startsWith(".") && !id.startsWith("/")) return null;
|
|
@@ -51,12 +76,12 @@ const unpluginFactory = (opts) => {
|
|
|
51
76
|
},
|
|
52
77
|
async load(id) {
|
|
53
78
|
const isDts = id.endsWith(".as.d.ts");
|
|
54
|
-
const sourceId = isDts ? id.slice(0, -
|
|
79
|
+
const sourceId = isDts ? id.slice(0, -5) : id;
|
|
55
80
|
if (sourceId.endsWith(".as")) {
|
|
56
81
|
if (!repo) {
|
|
57
82
|
const config = await getConfig();
|
|
58
|
-
if (!config.plugins) config.plugins = [(0,
|
|
59
|
-
repo = new
|
|
83
|
+
if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
|
|
84
|
+
repo = new _atscript_core.AtscriptRepo(getRoot(), config);
|
|
60
85
|
}
|
|
61
86
|
const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
|
|
62
87
|
const doc = await repo.openDocument(`file://${sourceId}`, code);
|
|
@@ -68,21 +93,17 @@ const unpluginFactory = (opts) => {
|
|
|
68
93
|
if (strict && !error) error = m.message;
|
|
69
94
|
} else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
|
|
70
95
|
if (error) throw new Error(error);
|
|
71
|
-
if (isDts) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
code: content,
|
|
76
|
-
map: null
|
|
77
|
-
};
|
|
78
|
-
}
|
|
96
|
+
if (isDts) return {
|
|
97
|
+
code: ((await doc.render("dts"))?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, ""),
|
|
98
|
+
map: null
|
|
99
|
+
};
|
|
79
100
|
const out = await doc.render("js");
|
|
80
|
-
const hasMutatingAnnotates = doc.nodes.some((n) => (0,
|
|
101
|
+
const hasMutatingAnnotates = doc.nodes.some((n) => (0, _atscript_core.isAnnotate)(n) && n.isMutating);
|
|
81
102
|
return {
|
|
82
103
|
code: out?.[0]?.content || "",
|
|
83
104
|
moduleType: "js",
|
|
84
105
|
map: null,
|
|
85
|
-
moduleSideEffects: hasMutatingAnnotates ?
|
|
106
|
+
moduleSideEffects: hasMutatingAnnotates ? void 0 : false
|
|
86
107
|
};
|
|
87
108
|
}
|
|
88
109
|
}
|
package/dist/rollup.d.ts
CHANGED
|
@@ -6,6 +6,20 @@ interface atscriptPluginOptions {
|
|
|
6
6
|
* @default true
|
|
7
7
|
*/
|
|
8
8
|
strict?: boolean;
|
|
9
|
+
/**
|
|
10
|
+
* The directory `atscript.config.*` is discovered from and `.as` files are
|
|
11
|
+
* resolved against. Absolute, or relative to `process.cwd()`.
|
|
12
|
+
*
|
|
13
|
+
* Defaults to the bundler's root (Vite: `config.root`, picked up automatically
|
|
14
|
+
* in `configResolved`) or `process.cwd()`.
|
|
15
|
+
*
|
|
16
|
+
* Vite picks the root up automatically; other bundlers need `root` when the
|
|
17
|
+
* working directory is not the project root (monorepo `pnpm -C`, editor-launched
|
|
18
|
+
* builds, a root that sits next to — not above — the config). Without it the
|
|
19
|
+
* config is discovered from the wrong directory and valid annotations from
|
|
20
|
+
* config-provided plugins (`@db.*`, `@ui.*`, …) are reported as unknown.
|
|
21
|
+
*/
|
|
22
|
+
root?: string;
|
|
9
23
|
}
|
|
10
24
|
|
|
11
25
|
declare const _default: (options?: atscriptPluginOptions | undefined) => rollup.Plugin<any> | rollup.Plugin<any>[];
|
package/dist/rollup.mjs
CHANGED
|
@@ -1,22 +1,43 @@
|
|
|
1
1
|
import { createRollupPlugin } 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
|
}
|