unplugin-atscript 0.0.16 → 0.0.18
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/index.cjs +15 -7
- package/dist/index.d.ts +9 -4
- package/dist/index.mjs +16 -7
- package/package.json +7 -5
package/dist/index.cjs
CHANGED
|
@@ -30,13 +30,14 @@ const fs_promises = __toESM(require("fs/promises"));
|
|
|
30
30
|
const unplugin = __toESM(require("unplugin"));
|
|
31
31
|
|
|
32
32
|
//#region packages/unplugin/src/index.ts
|
|
33
|
-
const
|
|
33
|
+
const atscriptPluginFactory = (opts) => {
|
|
34
34
|
const root = process.cwd();
|
|
35
|
-
let
|
|
35
|
+
let atscriptConfig = new Promise((resolve) => {
|
|
36
36
|
(0, __atscript_core.resolveConfigFile)(root).then((p) => {
|
|
37
|
-
(0, __atscript_core.loadConfig)(
|
|
37
|
+
(0, __atscript_core.loadConfig)(p).then(resolve);
|
|
38
38
|
});
|
|
39
39
|
});
|
|
40
|
+
const strict = opts?.strict ?? true;
|
|
40
41
|
let repo;
|
|
41
42
|
return {
|
|
42
43
|
name: "atscript",
|
|
@@ -46,26 +47,33 @@ const anscriptPluginFactory = () => {
|
|
|
46
47
|
async load(id) {
|
|
47
48
|
if (id.endsWith(".as")) {
|
|
48
49
|
if (!repo) {
|
|
49
|
-
const config = await
|
|
50
|
+
const config = await atscriptConfig;
|
|
50
51
|
if (!config.plugins) config.plugins = [(0, __atscript_typescript.default)()];
|
|
51
52
|
repo = new __atscript_core.AtscriptRepo(root, config);
|
|
52
53
|
}
|
|
53
54
|
const code = (await (0, fs_promises.readFile)(id, "utf8")).toString();
|
|
54
55
|
const doc = await repo.openDocument("file://" + id, code);
|
|
55
56
|
await repo.checkDoc(doc);
|
|
57
|
+
const messages = doc.getDiagMessages().reverse();
|
|
58
|
+
let error = "";
|
|
59
|
+
for (const m of messages) if (m.severity === 1) {
|
|
60
|
+
console.log(doc.renderDiagMessage(m, true, true));
|
|
61
|
+
if (strict && !error) error = m.message;
|
|
62
|
+
} else if (m.severity === 2) console.log(doc.renderDiagMessage(m, false, true));
|
|
63
|
+
if (error) throw new Error(error);
|
|
56
64
|
const out = await doc.render("js");
|
|
57
65
|
return {
|
|
58
66
|
code: out?.[0]?.content || "",
|
|
59
|
-
moduleType: "js"
|
|
67
|
+
moduleType: "js",
|
|
68
|
+
map: null
|
|
60
69
|
};
|
|
61
70
|
}
|
|
62
71
|
}
|
|
63
72
|
};
|
|
64
73
|
};
|
|
65
|
-
const asPlugin = /* #__PURE__ */ (0, unplugin.createUnplugin)(
|
|
74
|
+
const asPlugin = /* #__PURE__ */ (0, unplugin.createUnplugin)(atscriptPluginFactory);
|
|
66
75
|
var src_default = asPlugin;
|
|
67
76
|
|
|
68
77
|
//#endregion
|
|
69
|
-
exports.anscriptPluginFactory = anscriptPluginFactory
|
|
70
78
|
exports.asPlugin = asPlugin
|
|
71
79
|
exports.default = src_default
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import * as unplugin from 'unplugin';
|
|
2
|
-
import { UnpluginFactory } from 'unplugin';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
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
|
+
declare const asPlugin: unplugin.UnpluginInstance<atscriptPluginOptions | undefined, boolean>;
|
|
6
11
|
|
|
7
|
-
export {
|
|
12
|
+
export { asPlugin, type atscriptPluginOptions, asPlugin as default };
|
package/dist/index.mjs
CHANGED
|
@@ -5,13 +5,14 @@ import { readFile } from "fs/promises";
|
|
|
5
5
|
import { createUnplugin } from "unplugin";
|
|
6
6
|
|
|
7
7
|
//#region packages/unplugin/src/index.ts
|
|
8
|
-
const
|
|
8
|
+
const atscriptPluginFactory = (opts) => {
|
|
9
9
|
const root = process.cwd();
|
|
10
|
-
let
|
|
10
|
+
let atscriptConfig = new Promise((resolve) => {
|
|
11
11
|
resolveConfigFile(root).then((p) => {
|
|
12
|
-
loadConfig(
|
|
12
|
+
loadConfig(p).then(resolve);
|
|
13
13
|
});
|
|
14
14
|
});
|
|
15
|
+
const strict = opts?.strict ?? true;
|
|
15
16
|
let repo;
|
|
16
17
|
return {
|
|
17
18
|
name: "atscript",
|
|
@@ -21,24 +22,32 @@ const anscriptPluginFactory = () => {
|
|
|
21
22
|
async load(id) {
|
|
22
23
|
if (id.endsWith(".as")) {
|
|
23
24
|
if (!repo) {
|
|
24
|
-
const config = await
|
|
25
|
+
const config = await atscriptConfig;
|
|
25
26
|
if (!config.plugins) config.plugins = [ts()];
|
|
26
27
|
repo = new AtscriptRepo(root, config);
|
|
27
28
|
}
|
|
28
29
|
const code = (await readFile(id, "utf8")).toString();
|
|
29
30
|
const doc = await repo.openDocument("file://" + id, code);
|
|
30
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);
|
|
31
39
|
const out = await doc.render("js");
|
|
32
40
|
return {
|
|
33
41
|
code: out?.[0]?.content || "",
|
|
34
|
-
moduleType: "js"
|
|
42
|
+
moduleType: "js",
|
|
43
|
+
map: null
|
|
35
44
|
};
|
|
36
45
|
}
|
|
37
46
|
}
|
|
38
47
|
};
|
|
39
48
|
};
|
|
40
|
-
const asPlugin = /* #__PURE__ */ createUnplugin(
|
|
49
|
+
const asPlugin = /* #__PURE__ */ createUnplugin(atscriptPluginFactory);
|
|
41
50
|
var src_default = asPlugin;
|
|
42
51
|
|
|
43
52
|
//#endregion
|
|
44
|
-
export {
|
|
53
|
+
export { asPlugin, src_default as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "unplugin-atscript",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Atscript: Configuration and build plugins.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.mjs",
|
|
@@ -36,12 +36,14 @@
|
|
|
36
36
|
"homepage": "https://github.com/moostjs/atscript/tree/main/packages/unplugin#readme",
|
|
37
37
|
"license": "ISC",
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"unplugin": "^2.1.2"
|
|
40
|
-
"@atscript/core": "^0.0.16",
|
|
41
|
-
"@atscript/typescript": "^0.0.16"
|
|
39
|
+
"unplugin": "^2.1.2"
|
|
42
40
|
},
|
|
43
41
|
"devDependencies": {
|
|
44
|
-
"vitest": "
|
|
42
|
+
"vitest": "3.2.4"
|
|
43
|
+
},
|
|
44
|
+
"peerDependencies": {
|
|
45
|
+
"@atscript/core": "^0.0.18",
|
|
46
|
+
"@atscript/typescript": "^0.0.18"
|
|
45
47
|
},
|
|
46
48
|
"scripts": {
|
|
47
49
|
"pub": "pnpm publish --access public",
|