unplugin-atscript 0.1.21 → 0.1.23

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
@@ -8,6 +8,7 @@ An Unplugin for processing `.as` files using [Atscript](https://github.com/moost
8
8
  - Loads and processes `.as` files with Atscript
9
9
  - Generates JavaScript output
10
10
  - Compatible with Vite, Rollup, Rolldown, Webpack, Rspack, esbuild, and Farm
11
+ - Separate entry point for each bundler — import only what you need
11
12
 
12
13
  ## Installation
13
14
 
@@ -34,10 +35,10 @@ pnpm add -D unplugin-atscript @atscript/typescript
34
35
  ```ts
35
36
  // vite.config.ts
36
37
  import { defineConfig } from 'vite'
37
- import atscript from 'unplugin-atscript'
38
+ import atscript from 'unplugin-atscript/vite'
38
39
 
39
40
  export default defineConfig({
40
- plugins: [atscript.vite()],
41
+ plugins: [atscript()],
41
42
  })
42
43
  ```
43
44
 
@@ -45,7 +46,7 @@ export default defineConfig({
45
46
 
46
47
  ```ts
47
48
  // rollup.config.js
48
- import atscript from 'unplugin-atscript'
49
+ import atscript from 'unplugin-atscript/rollup'
49
50
 
50
51
  export default {
51
52
  input: 'src/main.ts',
@@ -53,7 +54,7 @@ export default {
53
54
  dir: 'dist',
54
55
  format: 'esm',
55
56
  },
56
- plugins: [atscript.rollup()],
57
+ plugins: [atscript()],
57
58
  }
58
59
  ```
59
60
 
@@ -61,27 +62,37 @@ export default {
61
62
 
62
63
  ```js
63
64
  // webpack.config.js
64
- const atscript = require('unplugin-atscript')
65
+ const atscript = require('unplugin-atscript/webpack')
65
66
 
66
67
  module.exports = {
67
- plugins: [atscript.webpack()],
68
+ plugins: [atscript()],
68
69
  }
69
70
  ```
70
71
 
71
72
  ### esbuild
72
73
 
73
74
  ```js
74
- import atscript from 'unplugin-atscript'
75
+ import atscript from 'unplugin-atscript/esbuild'
75
76
  import { build } from 'esbuild'
76
77
 
77
78
  build({
78
- plugins: [atscript.esbuild()],
79
+ plugins: [atscript()],
79
80
  })
80
81
  ```
81
82
 
82
- ### Rolldown / Rspack / Farm
83
+ ### Rolldown
83
84
 
84
- Use `atscript.rolldown()`, `atscript.rspack()`, or `atscript.farm()` respectively — same pattern as above.
85
+ ```js
86
+ import atscript from 'unplugin-atscript/rolldown'
87
+
88
+ export default {
89
+ plugins: [atscript()],
90
+ }
91
+ ```
92
+
93
+ ### Rspack / Farm
94
+
95
+ Use `unplugin-atscript/rspack` or `unplugin-atscript/farm` respectively — same pattern as above.
85
96
 
86
97
  ## How It Works
87
98
 
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ 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
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#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"));
30
+
31
+ //#region packages/unplugin/src/index.ts
32
+ const unpluginFactory = (opts) => {
33
+ const root = process.cwd();
34
+ const atscriptConfig = new Promise((resolve) => {
35
+ (0, __atscript_core.resolveConfigFile)(root).then((p) => {
36
+ (0, __atscript_core.loadConfig)(p).then(resolve);
37
+ });
38
+ });
39
+ const strict = opts?.strict ?? true;
40
+ let repo;
41
+ return {
42
+ name: "unplugin-atscript",
43
+ resolveId(id, importer) {
44
+ if (importer && id.endsWith(".as")) return path.default.join(path.default.dirname(importer), id);
45
+ },
46
+ async load(id) {
47
+ if (id.endsWith(".as")) {
48
+ if (!repo) {
49
+ const config = await atscriptConfig;
50
+ if (!config.plugins) config.plugins = [(0, __atscript_typescript.default)()];
51
+ repo = new __atscript_core.AtscriptRepo(root, config);
52
+ }
53
+ const code = (await (0, fs_promises.readFile)(id, "utf8")).toString();
54
+ const doc = await repo.openDocument(`file://${id}`, code);
55
+ await repo.checkDoc(doc);
56
+ const messages = doc.getDiagMessages().reverse();
57
+ let error = "";
58
+ for (const m of messages) if (m.severity === 1) {
59
+ console.log(doc.renderDiagMessage(m, true, true));
60
+ if (strict && !error) error = m.message;
61
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
62
+ if (error) throw new Error(error);
63
+ const out = await doc.render("js");
64
+ const hasMutatingAnnotates = doc.nodes.some((n) => (0, __atscript_core.isAnnotate)(n) && n.isMutating);
65
+ return {
66
+ code: out?.[0]?.content || "",
67
+ moduleType: "js",
68
+ map: null,
69
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
70
+ };
71
+ }
72
+ }
73
+ };
74
+ };
75
+
76
+ //#endregion
77
+ //#region packages/unplugin/src/esbuild.ts
78
+ var esbuild_default = (0, unplugin.createEsbuildPlugin)(unpluginFactory);
79
+
80
+ //#endregion
81
+ module.exports = esbuild_default;
@@ -0,0 +1,13 @@
1
+ import * as _unplugin from 'unplugin';
2
+
3
+ interface atscriptPluginOptions {
4
+ /**
5
+ * When strict: true, atscript will throw an error if any document is not valid.
6
+ * @default true
7
+ */
8
+ strict?: boolean;
9
+ }
10
+
11
+ declare const _default: (options?: atscriptPluginOptions | undefined) => _unplugin.EsbuildPlugin;
12
+
13
+ export { _default as default };
@@ -0,0 +1,57 @@
1
+ import { createEsbuildPlugin } from "unplugin";
2
+ import { readFile } from "fs/promises";
3
+ import path from "path";
4
+ import { AtscriptRepo, isAnnotate, loadConfig, resolveConfigFile } from "@atscript/core";
5
+ import ts from "@atscript/typescript";
6
+
7
+ //#region packages/unplugin/src/index.ts
8
+ const unpluginFactory = (opts) => {
9
+ const root = process.cwd();
10
+ const atscriptConfig = new Promise((resolve) => {
11
+ resolveConfigFile(root).then((p) => {
12
+ loadConfig(p).then(resolve);
13
+ });
14
+ });
15
+ const strict = opts?.strict ?? true;
16
+ let repo;
17
+ return {
18
+ name: "unplugin-atscript",
19
+ resolveId(id, importer) {
20
+ if (importer && id.endsWith(".as")) return path.join(path.dirname(importer), id);
21
+ },
22
+ async load(id) {
23
+ if (id.endsWith(".as")) {
24
+ if (!repo) {
25
+ const config = await atscriptConfig;
26
+ if (!config.plugins) config.plugins = [ts()];
27
+ repo = new AtscriptRepo(root, config);
28
+ }
29
+ const code = (await readFile(id, "utf8")).toString();
30
+ const doc = await repo.openDocument(`file://${id}`, code);
31
+ await repo.checkDoc(doc);
32
+ const messages = doc.getDiagMessages().reverse();
33
+ let error = "";
34
+ for (const m of messages) if (m.severity === 1) {
35
+ console.log(doc.renderDiagMessage(m, true, true));
36
+ if (strict && !error) error = m.message;
37
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
38
+ if (error) throw new Error(error);
39
+ const out = await doc.render("js");
40
+ const hasMutatingAnnotates = doc.nodes.some((n) => isAnnotate(n) && n.isMutating);
41
+ return {
42
+ code: out?.[0]?.content || "",
43
+ moduleType: "js",
44
+ map: null,
45
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
46
+ };
47
+ }
48
+ }
49
+ };
50
+ };
51
+
52
+ //#endregion
53
+ //#region packages/unplugin/src/esbuild.ts
54
+ var esbuild_default = createEsbuildPlugin(unpluginFactory);
55
+
56
+ //#endregion
57
+ export { esbuild_default as default };
package/dist/farm.cjs ADDED
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ 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
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#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"));
30
+
31
+ //#region packages/unplugin/src/index.ts
32
+ const unpluginFactory = (opts) => {
33
+ const root = process.cwd();
34
+ const atscriptConfig = new Promise((resolve) => {
35
+ (0, __atscript_core.resolveConfigFile)(root).then((p) => {
36
+ (0, __atscript_core.loadConfig)(p).then(resolve);
37
+ });
38
+ });
39
+ const strict = opts?.strict ?? true;
40
+ let repo;
41
+ return {
42
+ name: "unplugin-atscript",
43
+ resolveId(id, importer) {
44
+ if (importer && id.endsWith(".as")) return path.default.join(path.default.dirname(importer), id);
45
+ },
46
+ async load(id) {
47
+ if (id.endsWith(".as")) {
48
+ if (!repo) {
49
+ const config = await atscriptConfig;
50
+ if (!config.plugins) config.plugins = [(0, __atscript_typescript.default)()];
51
+ repo = new __atscript_core.AtscriptRepo(root, config);
52
+ }
53
+ const code = (await (0, fs_promises.readFile)(id, "utf8")).toString();
54
+ const doc = await repo.openDocument(`file://${id}`, code);
55
+ await repo.checkDoc(doc);
56
+ const messages = doc.getDiagMessages().reverse();
57
+ let error = "";
58
+ for (const m of messages) if (m.severity === 1) {
59
+ console.log(doc.renderDiagMessage(m, true, true));
60
+ if (strict && !error) error = m.message;
61
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
62
+ if (error) throw new Error(error);
63
+ const out = await doc.render("js");
64
+ const hasMutatingAnnotates = doc.nodes.some((n) => (0, __atscript_core.isAnnotate)(n) && n.isMutating);
65
+ return {
66
+ code: out?.[0]?.content || "",
67
+ moduleType: "js",
68
+ map: null,
69
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
70
+ };
71
+ }
72
+ }
73
+ };
74
+ };
75
+
76
+ //#endregion
77
+ //#region packages/unplugin/src/farm.ts
78
+ var farm_default = (0, unplugin.createFarmPlugin)(unpluginFactory);
79
+
80
+ //#endregion
81
+ module.exports = farm_default;
package/dist/farm.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ interface atscriptPluginOptions {
2
+ /**
3
+ * When strict: true, atscript will throw an error if any document is not valid.
4
+ * @default true
5
+ */
6
+ strict?: boolean;
7
+ }
8
+
9
+ declare const _default: (options?: atscriptPluginOptions | undefined) => JsPlugin;
10
+
11
+ export { _default as default };
package/dist/farm.mjs ADDED
@@ -0,0 +1,57 @@
1
+ import { createFarmPlugin } from "unplugin";
2
+ import { readFile } from "fs/promises";
3
+ import path from "path";
4
+ import { AtscriptRepo, isAnnotate, loadConfig, resolveConfigFile } from "@atscript/core";
5
+ import ts from "@atscript/typescript";
6
+
7
+ //#region packages/unplugin/src/index.ts
8
+ const unpluginFactory = (opts) => {
9
+ const root = process.cwd();
10
+ const atscriptConfig = new Promise((resolve) => {
11
+ resolveConfigFile(root).then((p) => {
12
+ loadConfig(p).then(resolve);
13
+ });
14
+ });
15
+ const strict = opts?.strict ?? true;
16
+ let repo;
17
+ return {
18
+ name: "unplugin-atscript",
19
+ resolveId(id, importer) {
20
+ if (importer && id.endsWith(".as")) return path.join(path.dirname(importer), id);
21
+ },
22
+ async load(id) {
23
+ if (id.endsWith(".as")) {
24
+ if (!repo) {
25
+ const config = await atscriptConfig;
26
+ if (!config.plugins) config.plugins = [ts()];
27
+ repo = new AtscriptRepo(root, config);
28
+ }
29
+ const code = (await readFile(id, "utf8")).toString();
30
+ const doc = await repo.openDocument(`file://${id}`, code);
31
+ await repo.checkDoc(doc);
32
+ const messages = doc.getDiagMessages().reverse();
33
+ let error = "";
34
+ for (const m of messages) if (m.severity === 1) {
35
+ console.log(doc.renderDiagMessage(m, true, true));
36
+ if (strict && !error) error = m.message;
37
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
38
+ if (error) throw new Error(error);
39
+ const out = await doc.render("js");
40
+ const hasMutatingAnnotates = doc.nodes.some((n) => isAnnotate(n) && n.isMutating);
41
+ return {
42
+ code: out?.[0]?.content || "",
43
+ moduleType: "js",
44
+ map: null,
45
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
46
+ };
47
+ }
48
+ }
49
+ };
50
+ };
51
+
52
+ //#endregion
53
+ //#region packages/unplugin/src/farm.ts
54
+ var farm_default = createFarmPlugin(unpluginFactory);
55
+
56
+ //#endregion
57
+ export { farm_default as default };
package/dist/index.cjs CHANGED
@@ -30,7 +30,7 @@ const __atscript_typescript = __toESM(require("@atscript/typescript"));
30
30
  const unplugin = __toESM(require("unplugin"));
31
31
 
32
32
  //#region packages/unplugin/src/index.ts
33
- const atscriptPluginFactory = (opts) => {
33
+ const unpluginFactory = (opts) => {
34
34
  const root = process.cwd();
35
35
  const atscriptConfig = new Promise((resolve) => {
36
36
  (0, __atscript_core.resolveConfigFile)(root).then((p) => {
@@ -40,7 +40,7 @@ const atscriptPluginFactory = (opts) => {
40
40
  const strict = opts?.strict ?? true;
41
41
  let repo;
42
42
  return {
43
- name: "atscript",
43
+ name: "unplugin-atscript",
44
44
  resolveId(id, importer) {
45
45
  if (importer && id.endsWith(".as")) return path.default.join(path.default.dirname(importer), id);
46
46
  },
@@ -73,9 +73,12 @@ const atscriptPluginFactory = (opts) => {
73
73
  }
74
74
  };
75
75
  };
76
- const asPlugin = /* #__PURE__ */ (0, unplugin.createUnplugin)(atscriptPluginFactory);
77
- var src_default = asPlugin;
76
+ const unplugin$1 = /* #__PURE__ */ (0, unplugin.createUnplugin)(unpluginFactory);
77
+ const asPlugin = unplugin$1;
78
+ var src_default = unplugin$1;
78
79
 
79
80
  //#endregion
80
81
  exports.asPlugin = asPlugin
81
- exports.default = src_default
82
+ exports.default = src_default
83
+ exports.unplugin = unplugin$1
84
+ exports.unpluginFactory = unpluginFactory
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import * as unplugin from 'unplugin';
1
+ import * as _unplugin from 'unplugin';
2
+ import { UnpluginFactory } from 'unplugin';
2
3
 
3
4
  interface atscriptPluginOptions {
4
5
  /**
@@ -7,7 +8,10 @@ interface atscriptPluginOptions {
7
8
  */
8
9
  strict?: boolean;
9
10
  }
10
- declare const asPlugin: unplugin.UnpluginInstance<atscriptPluginOptions | undefined, boolean>;
11
+ declare const unpluginFactory: UnpluginFactory<atscriptPluginOptions | undefined>;
12
+ declare const unplugin: _unplugin.UnpluginInstance<atscriptPluginOptions | undefined, boolean>;
13
+ /** @deprecated Use `import atscript from 'unplugin-atscript/vite'` (or /rollup, /webpack, etc.) instead */
14
+ declare const asPlugin: _unplugin.UnpluginInstance<atscriptPluginOptions | undefined, boolean>;
11
15
 
12
- export { asPlugin, asPlugin as default };
16
+ export { asPlugin, unplugin as default, unplugin, unpluginFactory };
13
17
  export type { atscriptPluginOptions };
package/dist/index.mjs CHANGED
@@ -5,7 +5,7 @@ import ts from "@atscript/typescript";
5
5
  import { createUnplugin } from "unplugin";
6
6
 
7
7
  //#region packages/unplugin/src/index.ts
8
- const atscriptPluginFactory = (opts) => {
8
+ const unpluginFactory = (opts) => {
9
9
  const root = process.cwd();
10
10
  const atscriptConfig = new Promise((resolve) => {
11
11
  resolveConfigFile(root).then((p) => {
@@ -15,7 +15,7 @@ const atscriptPluginFactory = (opts) => {
15
15
  const strict = opts?.strict ?? true;
16
16
  let repo;
17
17
  return {
18
- name: "atscript",
18
+ name: "unplugin-atscript",
19
19
  resolveId(id, importer) {
20
20
  if (importer && id.endsWith(".as")) return path.join(path.dirname(importer), id);
21
21
  },
@@ -48,8 +48,9 @@ const atscriptPluginFactory = (opts) => {
48
48
  }
49
49
  };
50
50
  };
51
- const asPlugin = /* #__PURE__ */ createUnplugin(atscriptPluginFactory);
52
- var src_default = asPlugin;
51
+ const unplugin = /* #__PURE__ */ createUnplugin(unpluginFactory);
52
+ const asPlugin = unplugin;
53
+ var src_default = unplugin;
53
54
 
54
55
  //#endregion
55
- export { asPlugin, src_default as default };
56
+ export { asPlugin, src_default as default, unplugin, unpluginFactory };
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ //#region rolldown:runtime
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ 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
+ });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
20
+ value: mod,
21
+ enumerable: true
22
+ }) : target, mod));
23
+
24
+ //#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"));
30
+
31
+ //#region packages/unplugin/src/index.ts
32
+ const unpluginFactory = (opts) => {
33
+ const root = process.cwd();
34
+ const atscriptConfig = new Promise((resolve) => {
35
+ (0, __atscript_core.resolveConfigFile)(root).then((p) => {
36
+ (0, __atscript_core.loadConfig)(p).then(resolve);
37
+ });
38
+ });
39
+ const strict = opts?.strict ?? true;
40
+ let repo;
41
+ return {
42
+ name: "unplugin-atscript",
43
+ resolveId(id, importer) {
44
+ if (importer && id.endsWith(".as")) return path.default.join(path.default.dirname(importer), id);
45
+ },
46
+ async load(id) {
47
+ if (id.endsWith(".as")) {
48
+ if (!repo) {
49
+ const config = await atscriptConfig;
50
+ if (!config.plugins) config.plugins = [(0, __atscript_typescript.default)()];
51
+ repo = new __atscript_core.AtscriptRepo(root, config);
52
+ }
53
+ const code = (await (0, fs_promises.readFile)(id, "utf8")).toString();
54
+ const doc = await repo.openDocument(`file://${id}`, code);
55
+ await repo.checkDoc(doc);
56
+ const messages = doc.getDiagMessages().reverse();
57
+ let error = "";
58
+ for (const m of messages) if (m.severity === 1) {
59
+ console.log(doc.renderDiagMessage(m, true, true));
60
+ if (strict && !error) error = m.message;
61
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
62
+ if (error) throw new Error(error);
63
+ const out = await doc.render("js");
64
+ const hasMutatingAnnotates = doc.nodes.some((n) => (0, __atscript_core.isAnnotate)(n) && n.isMutating);
65
+ return {
66
+ code: out?.[0]?.content || "",
67
+ moduleType: "js",
68
+ map: null,
69
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
70
+ };
71
+ }
72
+ }
73
+ };
74
+ };
75
+
76
+ //#endregion
77
+ //#region packages/unplugin/src/rolldown.ts
78
+ var rolldown_default = (0, unplugin.createRolldownPlugin)(unpluginFactory);
79
+
80
+ //#endregion
81
+ module.exports = rolldown_default;
@@ -0,0 +1,13 @@
1
+ import * as _unplugin from 'unplugin';
2
+
3
+ interface atscriptPluginOptions {
4
+ /**
5
+ * When strict: true, atscript will throw an error if any document is not valid.
6
+ * @default true
7
+ */
8
+ strict?: boolean;
9
+ }
10
+
11
+ declare const _default: (options?: atscriptPluginOptions | undefined) => _unplugin.RolldownPlugin<any> | _unplugin.RolldownPlugin<any>[];
12
+
13
+ export { _default as default };
@@ -0,0 +1,57 @@
1
+ import { createRolldownPlugin } from "unplugin";
2
+ import { readFile } from "fs/promises";
3
+ import path from "path";
4
+ import { AtscriptRepo, isAnnotate, loadConfig, resolveConfigFile } from "@atscript/core";
5
+ import ts from "@atscript/typescript";
6
+
7
+ //#region packages/unplugin/src/index.ts
8
+ const unpluginFactory = (opts) => {
9
+ const root = process.cwd();
10
+ const atscriptConfig = new Promise((resolve) => {
11
+ resolveConfigFile(root).then((p) => {
12
+ loadConfig(p).then(resolve);
13
+ });
14
+ });
15
+ const strict = opts?.strict ?? true;
16
+ let repo;
17
+ return {
18
+ name: "unplugin-atscript",
19
+ resolveId(id, importer) {
20
+ if (importer && id.endsWith(".as")) return path.join(path.dirname(importer), id);
21
+ },
22
+ async load(id) {
23
+ if (id.endsWith(".as")) {
24
+ if (!repo) {
25
+ const config = await atscriptConfig;
26
+ if (!config.plugins) config.plugins = [ts()];
27
+ repo = new AtscriptRepo(root, config);
28
+ }
29
+ const code = (await readFile(id, "utf8")).toString();
30
+ const doc = await repo.openDocument(`file://${id}`, code);
31
+ await repo.checkDoc(doc);
32
+ const messages = doc.getDiagMessages().reverse();
33
+ let error = "";
34
+ for (const m of messages) if (m.severity === 1) {
35
+ console.log(doc.renderDiagMessage(m, true, true));
36
+ if (strict && !error) error = m.message;
37
+ } else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
38
+ if (error) throw new Error(error);
39
+ const out = await doc.render("js");
40
+ const hasMutatingAnnotates = doc.nodes.some((n) => isAnnotate(n) && n.isMutating);
41
+ return {
42
+ code: out?.[0]?.content || "",
43
+ moduleType: "js",
44
+ map: null,
45
+ moduleSideEffects: hasMutatingAnnotates ? undefined : false
46
+ };
47
+ }
48
+ }
49
+ };
50
+ };
51
+
52
+ //#endregion
53
+ //#region packages/unplugin/src/rolldown.ts
54
+ var rolldown_default = createRolldownPlugin(unpluginFactory);
55
+
56
+ //#endregion
57
+ export { rolldown_default as default };