unplugin-atscript 0.1.89 → 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 CHANGED
@@ -40,12 +40,24 @@ module.exports = { plugins: [atscript()] }
40
40
 
41
41
  Also available: `unplugin-atscript/esbuild`, `unplugin-atscript/rolldown`, `unplugin-atscript/rspack`, `unplugin-atscript/farm`.
42
42
 
43
+ ## Options
44
+
45
+ Same options on every bundler entry:
46
+
47
+ | Option | Type | Default | Effect |
48
+ | -------- | --------- | ------------------- | -------------------------------------------------------------------------------------- |
49
+ | `strict` | `boolean` | `true` | Fail the build on parse/diagnostic **errors**. `false` = log errors but keep building. |
50
+ | `root` | `string` | bundler root or cwd | Directory `atscript.config.*` is discovered from. Absolute, or relative to the cwd. |
51
+
52
+ Vite picks the root up automatically (from `configResolved`); other bundlers need `root` when the working directory is not the project root.
53
+
43
54
  ## Features
44
55
 
45
56
  - Universal bundler support via dedicated entry points
46
57
  - Automatic `atscript.config.*` loading
47
58
  - Strict validation — build fails on `.as` errors by default (`strict: false` to disable)
48
59
  - Tree-shaking aware — marks non-mutating modules as side-effect-free
60
+ - On Vite, prebundles `@atscript/typescript/utils` so the first `.as`-backed route does not trigger a dep re-optimization reload
49
61
 
50
62
  ## Documentation
51
63
 
package/dist/esbuild.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
package/dist/esbuild.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.EsbuildPlugin;
package/dist/esbuild.mjs CHANGED
@@ -1,22 +1,43 @@
1
1
  import { createEsbuildPlugin } 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/farm.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
package/dist/farm.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) => JsPlugin;
package/dist/farm.mjs CHANGED
@@ -1,22 +1,43 @@
1
1
  import { createFarmPlugin } 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/index.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
 
28
28
  //#endregion
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -35,17 +36,37 @@ let unplugin = require("unplugin");
35
36
 
36
37
  //#region packages/unplugin/src/index.ts
37
38
  const RE_DTS = /\.d\.[cm]?ts$/;
39
+ const RUNTIME_ENTRY = "@atscript/typescript/utils";
40
+ function isResolvableFrom(specifier, from) {
41
+ try {
42
+ (0, module$1.createRequire)(path.default.join(from, "package.json")).resolve(specifier);
43
+ return true;
44
+ } catch {
45
+ return false;
46
+ }
47
+ }
38
48
  const unpluginFactory = (opts) => {
39
- const root = process.cwd();
49
+ const explicitRoot = opts?.root ? path.default.resolve(opts.root) : void 0;
50
+ let detectedRoot;
51
+ const getRoot = () => explicitRoot ?? detectedRoot ?? process.cwd();
40
52
  const strict = opts?.strict ?? true;
41
53
  let repo;
42
54
  let configPromise;
43
55
  const getConfig = () => configPromise ?? (configPromise = (async () => {
44
- const p = await (0, _atscript_core.resolveConfigFile)(root);
56
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
45
57
  return p ? (0, _atscript_core.loadConfig)(p) : {};
46
58
  })());
47
59
  return {
48
60
  name: "unplugin-atscript",
61
+ vite: {
62
+ config(userConfig) {
63
+ const root = path.default.resolve(explicitRoot ?? userConfig.root ?? process.cwd());
64
+ return (userConfig.optimizeDeps?.include?.includes(RUNTIME_ENTRY) ?? false) || !isResolvableFrom(RUNTIME_ENTRY, root) ? void 0 : { optimizeDeps: { include: [RUNTIME_ENTRY] } };
65
+ },
66
+ configResolved(config) {
67
+ detectedRoot = config.root;
68
+ }
69
+ },
49
70
  resolveId(id, importer) {
50
71
  if (importer && id.endsWith(".as")) {
51
72
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -61,7 +82,7 @@ const unpluginFactory = (opts) => {
61
82
  if (!repo) {
62
83
  const config = await getConfig();
63
84
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
64
- repo = new _atscript_core.AtscriptRepo(root, config);
85
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
65
86
  }
66
87
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
67
88
  const doc = await repo.openDocument(`file://${sourceId}`, code);
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 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/rolldown.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
@@ -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 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/rollup.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
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 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/rspack.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/vite.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/dist/webpack.cjs CHANGED
@@ -27,6 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  //#endregion
28
28
  let unplugin = require("unplugin");
29
29
  let fs_promises = require("fs/promises");
30
+ let module$1 = require("module");
30
31
  let path = require("path");
31
32
  path = __toESM(path);
32
33
  let _atscript_core = require("@atscript/core");
@@ -34,17 +35,37 @@ let _atscript_typescript = require("@atscript/typescript");
34
35
 
35
36
  //#region packages/unplugin/src/index.ts
36
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
+ }
37
47
  const unpluginFactory = (opts) => {
38
- 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();
39
51
  const strict = opts?.strict ?? true;
40
52
  let repo;
41
53
  let configPromise;
42
54
  const getConfig = () => configPromise ?? (configPromise = (async () => {
43
- const p = await (0, _atscript_core.resolveConfigFile)(root);
55
+ const p = await (0, _atscript_core.resolveConfigFile)(getRoot());
44
56
  return p ? (0, _atscript_core.loadConfig)(p) : {};
45
57
  })());
46
58
  return {
47
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
+ },
48
69
  resolveId(id, importer) {
49
70
  if (importer && id.endsWith(".as")) {
50
71
  if (!id.startsWith(".") && !id.startsWith("/")) return null;
@@ -60,7 +81,7 @@ const unpluginFactory = (opts) => {
60
81
  if (!repo) {
61
82
  const config = await getConfig();
62
83
  if (!config.plugins) config.plugins = [(0, _atscript_typescript.tsPlugin)()];
63
- repo = new _atscript_core.AtscriptRepo(root, config);
84
+ repo = new _atscript_core.AtscriptRepo(getRoot(), config);
64
85
  }
65
86
  const code = (await (0, fs_promises.readFile)(sourceId, "utf8")).toString();
66
87
  const doc = await repo.openDocument(`file://${sourceId}`, code);
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;
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 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;
@@ -32,7 +53,7 @@ const unpluginFactory = (opts) => {
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);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-atscript",
3
- "version": "0.1.89",
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.89",
86
- "@atscript/typescript": "^0.1.89"
85
+ "@atscript/core": "^0.1.90",
86
+ "@atscript/typescript": "^0.1.90"
87
87
  },
88
88
  "build": [
89
89
  {},