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/dist/rspack.cjs CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
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") 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) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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
- const unplugin = __toESM(require("unplugin"));
26
- const fs_promises = __toESM(require("fs/promises"));
27
- const path = __toESM(require("path"));
28
- const __atscript_core = __toESM(require("@atscript/core"));
29
- const __atscript_typescript = __toESM(require("@atscript/typescript"));
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 root = process.cwd();
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, __atscript_core.resolveConfigFile)(root);
40
- return p ? (0, __atscript_core.loadConfig)(p) : {};
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, -".d.ts".length) : id;
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, __atscript_typescript.tsPlugin)()];
59
- repo = new __atscript_core.AtscriptRepo(root, config);
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
- const out$1 = await doc.render("dts");
73
- const content = (out$1?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, "");
74
- return {
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, __atscript_core.isAnnotate)(n) && n.isMutating);
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 ? undefined : false
106
+ moduleSideEffects: hasMutatingAnnotates ? void 0 : false
86
107
  };
87
108
  }
88
109
  }
package/dist/rspack.d.ts CHANGED
@@ -4,6 +4,20 @@ interface atscriptPluginOptions {
4
4
  * @default true
5
5
  */
6
6
  strict?: boolean;
7
+ /**
8
+ * The directory `atscript.config.*` is discovered from and `.as` files are
9
+ * resolved against. Absolute, or relative to `process.cwd()`.
10
+ *
11
+ * Defaults to the bundler's root (Vite: `config.root`, picked up automatically
12
+ * in `configResolved`) or `process.cwd()`.
13
+ *
14
+ * Vite picks the root up automatically; other bundlers need `root` when the
15
+ * working directory is not the project root (monorepo `pnpm -C`, editor-launched
16
+ * builds, a root that sits next to — not above — the config). Without it the
17
+ * config is discovered from the wrong directory and valid annotations from
18
+ * config-provided plugins (`@db.*`, `@ui.*`, …) are reported as unknown.
19
+ */
20
+ root?: string;
7
21
  }
8
22
 
9
23
  declare const _default: (options?: atscriptPluginOptions | undefined) => RspackPluginInstance;
package/dist/rspack.mjs CHANGED
@@ -1,22 +1,43 @@
1
1
  import { createRspackPlugin } 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 root = process.cwd();
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(root);
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, -".d.ts".length) : id;
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(root, config);
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
- const out$1 = await doc.render("dts");
49
- const content = (out$1?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, "");
50
- return {
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 ? undefined : false
78
+ moduleSideEffects: hasMutatingAnnotates ? void 0 : false
62
79
  };
63
80
  }
64
81
  }
package/dist/vite.cjs CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
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") 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) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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
- const unplugin = __toESM(require("unplugin"));
26
- const fs_promises = __toESM(require("fs/promises"));
27
- const path = __toESM(require("path"));
28
- const __atscript_core = __toESM(require("@atscript/core"));
29
- const __atscript_typescript = __toESM(require("@atscript/typescript"));
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 root = process.cwd();
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, __atscript_core.resolveConfigFile)(root);
40
- return p ? (0, __atscript_core.loadConfig)(p) : {};
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, -".d.ts".length) : id;
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, __atscript_typescript.tsPlugin)()];
59
- repo = new __atscript_core.AtscriptRepo(root, config);
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
- const out$1 = await doc.render("dts");
73
- const content = (out$1?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, "");
74
- return {
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, __atscript_core.isAnnotate)(n) && n.isMutating);
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 ? undefined : false
106
+ moduleSideEffects: hasMutatingAnnotates ? void 0 : false
86
107
  };
87
108
  }
88
109
  }
package/dist/vite.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) => _unplugin.VitePlugin<any> | _unplugin.VitePlugin<any>[];
package/dist/vite.mjs CHANGED
@@ -1,22 +1,43 @@
1
1
  import { createVitePlugin } 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 root = process.cwd();
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(root);
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, -".d.ts".length) : id;
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(root, config);
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
- const out$1 = await doc.render("dts");
49
- const content = (out$1?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, "");
50
- return {
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 ? undefined : false
78
+ moduleSideEffects: hasMutatingAnnotates ? void 0 : false
62
79
  };
63
80
  }
64
81
  }
package/dist/webpack.cjs CHANGED
@@ -1,5 +1,4 @@
1
- "use strict";
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") 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) __defProp(to, key, {
13
- get: ((k) => from[k]).bind(null, key),
14
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
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
- const unplugin = __toESM(require("unplugin"));
26
- const fs_promises = __toESM(require("fs/promises"));
27
- const path = __toESM(require("path"));
28
- const __atscript_core = __toESM(require("@atscript/core"));
29
- const __atscript_typescript = __toESM(require("@atscript/typescript"));
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 root = process.cwd();
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, __atscript_core.resolveConfigFile)(root);
40
- return p ? (0, __atscript_core.loadConfig)(p) : {};
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, -".d.ts".length) : id;
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, __atscript_typescript.tsPlugin)()];
59
- repo = new __atscript_core.AtscriptRepo(root, config);
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
- const out$1 = await doc.render("dts");
73
- const content = (out$1?.[0]?.content || "").replace(/^\/{3}\s*<reference\s+path=[^\n]*\n/m, "");
74
- return {
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, __atscript_core.isAnnotate)(n) && n.isMutating);
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 ? undefined : false
106
+ moduleSideEffects: hasMutatingAnnotates ? void 0 : false
86
107
  };
87
108
  }
88
109
  }
package/dist/webpack.d.ts CHANGED
@@ -4,6 +4,20 @@ interface atscriptPluginOptions {
4
4
  * @default true
5
5
  */
6
6
  strict?: boolean;
7
+ /**
8
+ * The directory `atscript.config.*` is discovered from and `.as` files are
9
+ * resolved against. Absolute, or relative to `process.cwd()`.
10
+ *
11
+ * Defaults to the bundler's root (Vite: `config.root`, picked up automatically
12
+ * in `configResolved`) or `process.cwd()`.
13
+ *
14
+ * Vite picks the root up automatically; other bundlers need `root` when the
15
+ * working directory is not the project root (monorepo `pnpm -C`, editor-launched
16
+ * builds, a root that sits next to — not above — the config). Without it the
17
+ * config is discovered from the wrong directory and valid annotations from
18
+ * config-provided plugins (`@db.*`, `@ui.*`, …) are reported as unknown.
19
+ */
20
+ root?: string;
7
21
  }
8
22
 
9
23
  declare const _default: (options?: atscriptPluginOptions | undefined) => WebpackPluginInstance;