@animus-ui/layergate 0.0.0-stage → 0.1.35
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 +239 -2
- package/dist/compile-C4GyCiuY.cjs +323 -0
- package/dist/compile-Cu_GFS3l.mjs +295 -0
- package/dist/compile-DZwVBjTM.d.cts +126 -0
- package/dist/compile-DZwVBjTM.d.cts.map +1 -0
- package/dist/compile-DZwVBjTM.d.mts +126 -0
- package/dist/compile-DZwVBjTM.d.mts.map +1 -0
- package/dist/host-BGcb1rMJ.mjs +169 -0
- package/dist/host-C4ZaMdkx.cjs +210 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +3 -0
- package/dist/index.d.mts +3 -0
- package/dist/index.mjs +3 -0
- package/dist/plan-Bsn_yxS9.mjs +29 -0
- package/dist/plan-hvk04qzh.cjs +40 -0
- package/dist/plan-w-y0limy.d.cts +35 -0
- package/dist/plan-w-y0limy.d.cts.map +1 -0
- package/dist/plan-w-y0limy.d.mts +35 -0
- package/dist/plan-w-y0limy.d.mts.map +1 -0
- package/dist/sheet-BUnyt5Jt.cjs +576 -0
- package/dist/sheet-DJGhbeYI.mjs +571 -0
- package/dist/vite.cjs +295 -0
- package/dist/vite.d.cts +59 -0
- package/dist/vite.d.cts.map +1 -0
- package/dist/vite.d.mts +59 -0
- package/dist/vite.d.mts.map +1 -0
- package/dist/vite.mjs +290 -0
- package/dist/webpack-loader.cjs +104 -0
- package/dist/webpack-loader.d.cts +35 -0
- package/dist/webpack-loader.d.cts.map +1 -0
- package/dist/webpack-loader.d.mts +36 -0
- package/dist/webpack-loader.d.mts.map +1 -0
- package/dist/webpack-loader.mjs +104 -0
- package/dist/webpack-state-BpF2PPjA.d.cts +15 -0
- package/dist/webpack-state-BpF2PPjA.d.cts.map +1 -0
- package/dist/webpack-state-BtmtzsWZ.cjs +61 -0
- package/dist/webpack-state-CXoQQ7XR.d.mts +15 -0
- package/dist/webpack-state-CXoQQ7XR.d.mts.map +1 -0
- package/dist/webpack-state-DwltSkQq.mjs +44 -0
- package/dist/webpack.cjs +161 -0
- package/dist/webpack.d.cts +98 -0
- package/dist/webpack.d.cts.map +1 -0
- package/dist/webpack.d.mts +98 -0
- package/dist/webpack.d.mts.map +1 -0
- package/dist/webpack.mjs +155 -0
- package/package.json +90 -4
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
import { t as readSheet } from "./sheet-DJGhbeYI.mjs";
|
|
2
|
+
import { dirname, join, posix } from "node:path";
|
|
3
|
+
import { readFileSync, realpathSync } from "node:fs";
|
|
4
|
+
//#region src/host.ts
|
|
5
|
+
/**
|
|
6
|
+
* What every host adapter shares: file identity by realpath, which files
|
|
7
|
+
* the plan owns (declared sheets, and listed dependencies by the package
|
|
8
|
+
* that holds them), whether a stylesheet reaches an owned file, and how a
|
|
9
|
+
* diagnostic prints.
|
|
10
|
+
*/
|
|
11
|
+
/** A path with forward slashes, normalized. */
|
|
12
|
+
const slashes = (path) => posix.normalize(path.replace(/\\/g, "/"));
|
|
13
|
+
/** A path through symlinks, with forward slashes. */
|
|
14
|
+
function real(path) {
|
|
15
|
+
try {
|
|
16
|
+
return slashes(realpathSync(path));
|
|
17
|
+
} catch {
|
|
18
|
+
return slashes(path);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** A module id's file, without its query, by realpath. */
|
|
22
|
+
const fileOf = (id) => real(id.split("?")[0]);
|
|
23
|
+
/** Resolves each of `specifiers`, a plan's `what` list, with `resolveOne`;
|
|
24
|
+
* one that resolves to nothing fails, naming it. */
|
|
25
|
+
function resolveEach(specifiers, what, root, resolveOne) {
|
|
26
|
+
return Promise.all(specifiers.map(async (specifier) => {
|
|
27
|
+
const file = await resolveOne(specifier);
|
|
28
|
+
if (!file) throw new Error(`[layergate] ${what}: cannot resolve "${specifier}" from ${root}`);
|
|
29
|
+
return file;
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/** The nearest `package.json` above `dir`: its directory and name. */
|
|
33
|
+
function packageOf(dir, cache) {
|
|
34
|
+
const visited = [];
|
|
35
|
+
let current = dir;
|
|
36
|
+
let found = null;
|
|
37
|
+
for (;;) {
|
|
38
|
+
if (cache.has(current)) {
|
|
39
|
+
found = cache.get(current);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
visited.push(current);
|
|
43
|
+
try {
|
|
44
|
+
const { name } = JSON.parse(readFileSync(join(current, "package.json"), "utf8"));
|
|
45
|
+
found = {
|
|
46
|
+
dir: current,
|
|
47
|
+
name: name ?? ""
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
} catch {
|
|
51
|
+
const parent = dirname(current);
|
|
52
|
+
if (parent === current) break;
|
|
53
|
+
current = parent;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const dirVisited of visited) cache.set(dirVisited, found);
|
|
57
|
+
return found;
|
|
58
|
+
}
|
|
59
|
+
/** Which files a plan owns, by realpath: a declared sheet, or a file of a
|
|
60
|
+
* listed dependency, a package other than the app's (`root`'s). */
|
|
61
|
+
function ownership(plan) {
|
|
62
|
+
const packages = /* @__PURE__ */ new Map();
|
|
63
|
+
let app = null;
|
|
64
|
+
let declared = [];
|
|
65
|
+
return {
|
|
66
|
+
/** Sets the app root and the declared sheets, by realpath. */
|
|
67
|
+
reset(root, sheets) {
|
|
68
|
+
app = packageOf(real(root), packages);
|
|
69
|
+
declared = sheets;
|
|
70
|
+
},
|
|
71
|
+
get declared() {
|
|
72
|
+
return declared;
|
|
73
|
+
},
|
|
74
|
+
/** Whether the plan can own anything at all. */
|
|
75
|
+
owning: () => declared.length > 0 || plan.dependencies !== false,
|
|
76
|
+
owns(file) {
|
|
77
|
+
if (declared.includes(file)) return true;
|
|
78
|
+
if (plan.dependencies === false) return false;
|
|
79
|
+
const owner = packageOf(dirname(file), packages);
|
|
80
|
+
if (!owner || owner.dir === app?.dir) return false;
|
|
81
|
+
return plan.dependencies === true || plan.dependencies.has(owner.name);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Whether the stylesheet `file`, whose `@import`s are `imports`, reaches
|
|
86
|
+
* an owned file: resolved only, never compiled. */
|
|
87
|
+
async function reachesOwned(file, imports, options, seen = /* @__PURE__ */ new Set()) {
|
|
88
|
+
if (seen.has(file)) return false;
|
|
89
|
+
seen.add(file);
|
|
90
|
+
if (options.owns(file)) return true;
|
|
91
|
+
for (const statement of imports) {
|
|
92
|
+
const child = await options.resolve(statement.url, file);
|
|
93
|
+
if (!child) continue;
|
|
94
|
+
if (await reachesOwned(child, (options.parsed?.get(child)?.sheet ?? readSheet(await options.read(child).catch(() => ""))).imports, options, seen)) return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a host keeps between compiles: parsed files, the files each
|
|
100
|
+
* finished stylesheet (a unit) read, and whether a stylesheet reaches an
|
|
101
|
+
* owned file, each kept until a file it depends on changes.
|
|
102
|
+
*/
|
|
103
|
+
var Units = class {
|
|
104
|
+
/** Parsed files, for `compileUnit`'s `cache`. */
|
|
105
|
+
parsed = /* @__PURE__ */ new Map();
|
|
106
|
+
filesByUnit = /* @__PURE__ */ new Map();
|
|
107
|
+
unitsByFile = /* @__PURE__ */ new Map();
|
|
108
|
+
reached = /* @__PURE__ */ new Map();
|
|
109
|
+
realpaths = /* @__PURE__ */ new Map();
|
|
110
|
+
/** `file` by realpath, the identity ownership, opt-outs and the declared
|
|
111
|
+
* sheets are decided by, wherever a host reads it from. */
|
|
112
|
+
canonical(file) {
|
|
113
|
+
let path = this.realpaths.get(file);
|
|
114
|
+
if (path === void 0) this.realpaths.set(file, path = real(file));
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
/** Records the files `unit` read. Returns the files no unit reads any
|
|
118
|
+
* more, whose parses are forgotten. */
|
|
119
|
+
record(unit, files) {
|
|
120
|
+
const current = new Set(files);
|
|
121
|
+
const forgotten = [];
|
|
122
|
+
for (const file of this.filesByUnit.get(unit) ?? []) {
|
|
123
|
+
if (current.has(file)) continue;
|
|
124
|
+
const units = this.unitsByFile.get(file);
|
|
125
|
+
units?.delete(unit);
|
|
126
|
+
if (units?.size === 0) {
|
|
127
|
+
this.unitsByFile.delete(file);
|
|
128
|
+
this.parsed.delete(file);
|
|
129
|
+
forgotten.push(file);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.filesByUnit.set(unit, current);
|
|
133
|
+
for (const file of current) {
|
|
134
|
+
let units = this.unitsByFile.get(file);
|
|
135
|
+
if (!units) this.unitsByFile.set(file, units = /* @__PURE__ */ new Set());
|
|
136
|
+
units.add(unit);
|
|
137
|
+
}
|
|
138
|
+
return forgotten;
|
|
139
|
+
}
|
|
140
|
+
/** Whether a finished stylesheet read `file`. */
|
|
141
|
+
reads(file) {
|
|
142
|
+
return this.unitsByFile.has(file);
|
|
143
|
+
}
|
|
144
|
+
/** Forgets `file`'s parse and every reach answer, and returns the units
|
|
145
|
+
* that read it. */
|
|
146
|
+
changed(file) {
|
|
147
|
+
this.parsed.delete(file);
|
|
148
|
+
this.realpaths.delete(file);
|
|
149
|
+
this.reached.clear();
|
|
150
|
+
return this.unitsByFile.get(file) ?? /* @__PURE__ */ new Set();
|
|
151
|
+
}
|
|
152
|
+
/** `reachesOwned`, answered once per file until a file changes. */
|
|
153
|
+
async reaches(file, imports, options) {
|
|
154
|
+
let reached = this.reached.get(file);
|
|
155
|
+
if (reached === void 0) {
|
|
156
|
+
reached = await reachesOwned(file, imports, {
|
|
157
|
+
...options,
|
|
158
|
+
parsed: this.parsed
|
|
159
|
+
});
|
|
160
|
+
this.reached.set(file, reached);
|
|
161
|
+
}
|
|
162
|
+
return reached;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
function formatDiagnostic(diagnostic) {
|
|
166
|
+
return `[layergate] ${diagnostic.file ? `${diagnostic.file}${diagnostic.line ? `:${diagnostic.line}:${diagnostic.column}` : ""}: ` : ""}${diagnostic.message} [${diagnostic.code}]`;
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
export { real as a, ownership as i, fileOf as n, resolveEach as o, formatDiagnostic as r, slashes as s, Units as t };
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
const require_sheet = require("./sheet-BUnyt5Jt.cjs");
|
|
2
|
+
let node_path = require("node:path");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
//#region src/host.ts
|
|
5
|
+
/**
|
|
6
|
+
* What every host adapter shares: file identity by realpath, which files
|
|
7
|
+
* the plan owns (declared sheets, and listed dependencies by the package
|
|
8
|
+
* that holds them), whether a stylesheet reaches an owned file, and how a
|
|
9
|
+
* diagnostic prints.
|
|
10
|
+
*/
|
|
11
|
+
/** A path with forward slashes, normalized. */
|
|
12
|
+
const slashes = (path) => node_path.posix.normalize(path.replace(/\\/g, "/"));
|
|
13
|
+
/** A path through symlinks, with forward slashes. */
|
|
14
|
+
function real(path) {
|
|
15
|
+
try {
|
|
16
|
+
return slashes((0, node_fs.realpathSync)(path));
|
|
17
|
+
} catch {
|
|
18
|
+
return slashes(path);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
/** A module id's file, without its query, by realpath. */
|
|
22
|
+
const fileOf = (id) => real(id.split("?")[0]);
|
|
23
|
+
/** Resolves each of `specifiers`, a plan's `what` list, with `resolveOne`;
|
|
24
|
+
* one that resolves to nothing fails, naming it. */
|
|
25
|
+
function resolveEach(specifiers, what, root, resolveOne) {
|
|
26
|
+
return Promise.all(specifiers.map(async (specifier) => {
|
|
27
|
+
const file = await resolveOne(specifier);
|
|
28
|
+
if (!file) throw new Error(`[layergate] ${what}: cannot resolve "${specifier}" from ${root}`);
|
|
29
|
+
return file;
|
|
30
|
+
}));
|
|
31
|
+
}
|
|
32
|
+
/** The nearest `package.json` above `dir`: its directory and name. */
|
|
33
|
+
function packageOf(dir, cache) {
|
|
34
|
+
const visited = [];
|
|
35
|
+
let current = dir;
|
|
36
|
+
let found = null;
|
|
37
|
+
for (;;) {
|
|
38
|
+
if (cache.has(current)) {
|
|
39
|
+
found = cache.get(current);
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
visited.push(current);
|
|
43
|
+
try {
|
|
44
|
+
const { name } = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(current, "package.json"), "utf8"));
|
|
45
|
+
found = {
|
|
46
|
+
dir: current,
|
|
47
|
+
name: name ?? ""
|
|
48
|
+
};
|
|
49
|
+
break;
|
|
50
|
+
} catch {
|
|
51
|
+
const parent = (0, node_path.dirname)(current);
|
|
52
|
+
if (parent === current) break;
|
|
53
|
+
current = parent;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const dirVisited of visited) cache.set(dirVisited, found);
|
|
57
|
+
return found;
|
|
58
|
+
}
|
|
59
|
+
/** Which files a plan owns, by realpath: a declared sheet, or a file of a
|
|
60
|
+
* listed dependency, a package other than the app's (`root`'s). */
|
|
61
|
+
function ownership(plan) {
|
|
62
|
+
const packages = /* @__PURE__ */ new Map();
|
|
63
|
+
let app = null;
|
|
64
|
+
let declared = [];
|
|
65
|
+
return {
|
|
66
|
+
/** Sets the app root and the declared sheets, by realpath. */
|
|
67
|
+
reset(root, sheets) {
|
|
68
|
+
app = packageOf(real(root), packages);
|
|
69
|
+
declared = sheets;
|
|
70
|
+
},
|
|
71
|
+
get declared() {
|
|
72
|
+
return declared;
|
|
73
|
+
},
|
|
74
|
+
/** Whether the plan can own anything at all. */
|
|
75
|
+
owning: () => declared.length > 0 || plan.dependencies !== false,
|
|
76
|
+
owns(file) {
|
|
77
|
+
if (declared.includes(file)) return true;
|
|
78
|
+
if (plan.dependencies === false) return false;
|
|
79
|
+
const owner = packageOf((0, node_path.dirname)(file), packages);
|
|
80
|
+
if (!owner || owner.dir === app?.dir) return false;
|
|
81
|
+
return plan.dependencies === true || plan.dependencies.has(owner.name);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/** Whether the stylesheet `file`, whose `@import`s are `imports`, reaches
|
|
86
|
+
* an owned file: resolved only, never compiled. */
|
|
87
|
+
async function reachesOwned(file, imports, options, seen = /* @__PURE__ */ new Set()) {
|
|
88
|
+
if (seen.has(file)) return false;
|
|
89
|
+
seen.add(file);
|
|
90
|
+
if (options.owns(file)) return true;
|
|
91
|
+
for (const statement of imports) {
|
|
92
|
+
const child = await options.resolve(statement.url, file);
|
|
93
|
+
if (!child) continue;
|
|
94
|
+
if (await reachesOwned(child, (options.parsed?.get(child)?.sheet ?? require_sheet.readSheet(await options.read(child).catch(() => ""))).imports, options, seen)) return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* What a host keeps between compiles: parsed files, the files each
|
|
100
|
+
* finished stylesheet (a unit) read, and whether a stylesheet reaches an
|
|
101
|
+
* owned file, each kept until a file it depends on changes.
|
|
102
|
+
*/
|
|
103
|
+
var Units = class {
|
|
104
|
+
/** Parsed files, for `compileUnit`'s `cache`. */
|
|
105
|
+
parsed = /* @__PURE__ */ new Map();
|
|
106
|
+
filesByUnit = /* @__PURE__ */ new Map();
|
|
107
|
+
unitsByFile = /* @__PURE__ */ new Map();
|
|
108
|
+
reached = /* @__PURE__ */ new Map();
|
|
109
|
+
realpaths = /* @__PURE__ */ new Map();
|
|
110
|
+
/** `file` by realpath, the identity ownership, opt-outs and the declared
|
|
111
|
+
* sheets are decided by, wherever a host reads it from. */
|
|
112
|
+
canonical(file) {
|
|
113
|
+
let path = this.realpaths.get(file);
|
|
114
|
+
if (path === void 0) this.realpaths.set(file, path = real(file));
|
|
115
|
+
return path;
|
|
116
|
+
}
|
|
117
|
+
/** Records the files `unit` read. Returns the files no unit reads any
|
|
118
|
+
* more, whose parses are forgotten. */
|
|
119
|
+
record(unit, files) {
|
|
120
|
+
const current = new Set(files);
|
|
121
|
+
const forgotten = [];
|
|
122
|
+
for (const file of this.filesByUnit.get(unit) ?? []) {
|
|
123
|
+
if (current.has(file)) continue;
|
|
124
|
+
const units = this.unitsByFile.get(file);
|
|
125
|
+
units?.delete(unit);
|
|
126
|
+
if (units?.size === 0) {
|
|
127
|
+
this.unitsByFile.delete(file);
|
|
128
|
+
this.parsed.delete(file);
|
|
129
|
+
forgotten.push(file);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
this.filesByUnit.set(unit, current);
|
|
133
|
+
for (const file of current) {
|
|
134
|
+
let units = this.unitsByFile.get(file);
|
|
135
|
+
if (!units) this.unitsByFile.set(file, units = /* @__PURE__ */ new Set());
|
|
136
|
+
units.add(unit);
|
|
137
|
+
}
|
|
138
|
+
return forgotten;
|
|
139
|
+
}
|
|
140
|
+
/** Whether a finished stylesheet read `file`. */
|
|
141
|
+
reads(file) {
|
|
142
|
+
return this.unitsByFile.has(file);
|
|
143
|
+
}
|
|
144
|
+
/** Forgets `file`'s parse and every reach answer, and returns the units
|
|
145
|
+
* that read it. */
|
|
146
|
+
changed(file) {
|
|
147
|
+
this.parsed.delete(file);
|
|
148
|
+
this.realpaths.delete(file);
|
|
149
|
+
this.reached.clear();
|
|
150
|
+
return this.unitsByFile.get(file) ?? /* @__PURE__ */ new Set();
|
|
151
|
+
}
|
|
152
|
+
/** `reachesOwned`, answered once per file until a file changes. */
|
|
153
|
+
async reaches(file, imports, options) {
|
|
154
|
+
let reached = this.reached.get(file);
|
|
155
|
+
if (reached === void 0) {
|
|
156
|
+
reached = await reachesOwned(file, imports, {
|
|
157
|
+
...options,
|
|
158
|
+
parsed: this.parsed
|
|
159
|
+
});
|
|
160
|
+
this.reached.set(file, reached);
|
|
161
|
+
}
|
|
162
|
+
return reached;
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
function formatDiagnostic(diagnostic) {
|
|
166
|
+
return `[layergate] ${diagnostic.file ? `${diagnostic.file}${diagnostic.line ? `:${diagnostic.line}:${diagnostic.column}` : ""}: ` : ""}${diagnostic.message} [${diagnostic.code}]`;
|
|
167
|
+
}
|
|
168
|
+
//#endregion
|
|
169
|
+
Object.defineProperty(exports, "Units", {
|
|
170
|
+
enumerable: true,
|
|
171
|
+
get: function() {
|
|
172
|
+
return Units;
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
Object.defineProperty(exports, "fileOf", {
|
|
176
|
+
enumerable: true,
|
|
177
|
+
get: function() {
|
|
178
|
+
return fileOf;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
Object.defineProperty(exports, "formatDiagnostic", {
|
|
182
|
+
enumerable: true,
|
|
183
|
+
get: function() {
|
|
184
|
+
return formatDiagnostic;
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
Object.defineProperty(exports, "ownership", {
|
|
188
|
+
enumerable: true,
|
|
189
|
+
get: function() {
|
|
190
|
+
return ownership;
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
Object.defineProperty(exports, "real", {
|
|
194
|
+
enumerable: true,
|
|
195
|
+
get: function() {
|
|
196
|
+
return real;
|
|
197
|
+
}
|
|
198
|
+
});
|
|
199
|
+
Object.defineProperty(exports, "resolveEach", {
|
|
200
|
+
enumerable: true,
|
|
201
|
+
get: function() {
|
|
202
|
+
return resolveEach;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
Object.defineProperty(exports, "slashes", {
|
|
206
|
+
enumerable: true,
|
|
207
|
+
get: function() {
|
|
208
|
+
return slashes;
|
|
209
|
+
}
|
|
210
|
+
});
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_compile = require("./compile-C4GyCiuY.cjs");
|
|
3
|
+
const require_plan = require("./plan-hvk04qzh.cjs");
|
|
4
|
+
exports.LayergateConfigError = require_plan.LayergateConfigError;
|
|
5
|
+
exports.compileUnit = require_compile.compileUnit;
|
|
6
|
+
exports.resolvePlan = require_plan.resolvePlan;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as Severity, i as ParsedSheet, n as CompiledUnit, o as compileUnit, r as LayergateDiagnostic, t as CompileOptions } from "./compile-DZwVBjTM.cjs";
|
|
2
|
+
import { i as resolvePlan, n as LayergateOptions, r as LayergatePlan, t as LayergateConfigError } from "./plan-w-y0limy.cjs";
|
|
3
|
+
export { type CompileOptions, type CompiledUnit, LayergateConfigError, type LayergateDiagnostic, type LayergateOptions, type LayergatePlan, type ParsedSheet, type Severity, compileUnit, resolvePlan };
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as Severity, i as ParsedSheet, n as CompiledUnit, o as compileUnit, r as LayergateDiagnostic, t as CompileOptions } from "./compile-DZwVBjTM.mjs";
|
|
2
|
+
import { i as resolvePlan, n as LayergateOptions, r as LayergatePlan, t as LayergateConfigError } from "./plan-w-y0limy.mjs";
|
|
3
|
+
export { type CompileOptions, type CompiledUnit, LayergateConfigError, type LayergateDiagnostic, type LayergateOptions, type LayergatePlan, type ParsedSheet, type Severity, compileUnit, resolvePlan };
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//#region src/plan.ts
|
|
2
|
+
/** A layer name: identifiers joined by dots. */
|
|
3
|
+
const LAYER_NAME = /^-?[_a-zA-Z][\w-]*(?:\.-?[_a-zA-Z][\w-]*)*$/;
|
|
4
|
+
var LayergateConfigError = class extends Error {
|
|
5
|
+
name = "LayergateConfigError";
|
|
6
|
+
};
|
|
7
|
+
/** The plan `options` describe, or a `LayergateConfigError`. */
|
|
8
|
+
function resolvePlan(options = {}) {
|
|
9
|
+
const layer = options.layer ?? "vendor";
|
|
10
|
+
if (!LAYER_NAME.test(layer)) throw new LayergateConfigError(`layer "${layer}" is not a layer name`);
|
|
11
|
+
const order = options.order ?? [layer];
|
|
12
|
+
for (const name of order) if (!LAYER_NAME.test(name)) throw new LayergateConfigError(`order: "${name}" is not a layer name`);
|
|
13
|
+
const duplicate = order.find((name, index) => order.indexOf(name) !== index);
|
|
14
|
+
if (duplicate) throw new LayergateConfigError(`order: "${duplicate}" appears twice`);
|
|
15
|
+
if (!order.includes(layer)) throw new LayergateConfigError(`order must include the quarantine layer "${layer}"`);
|
|
16
|
+
const optOut = options.optOut ?? [];
|
|
17
|
+
const glob = optOut.find((entry) => /[*?[\]{}]/.test(entry));
|
|
18
|
+
if (glob) throw new LayergateConfigError(`optOut: "${glob}" is a pattern; list exact files`);
|
|
19
|
+
const dependencies = options.dependencies ?? false;
|
|
20
|
+
return {
|
|
21
|
+
layer,
|
|
22
|
+
order,
|
|
23
|
+
sheets: options.sheets ?? [],
|
|
24
|
+
dependencies: dependencies === true || dependencies === false ? dependencies : new Set(dependencies),
|
|
25
|
+
optOut
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
export { resolvePlan as n, LayergateConfigError as t };
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/plan.ts
|
|
2
|
+
/** A layer name: identifiers joined by dots. */
|
|
3
|
+
const LAYER_NAME = /^-?[_a-zA-Z][\w-]*(?:\.-?[_a-zA-Z][\w-]*)*$/;
|
|
4
|
+
var LayergateConfigError = class extends Error {
|
|
5
|
+
name = "LayergateConfigError";
|
|
6
|
+
};
|
|
7
|
+
/** The plan `options` describe, or a `LayergateConfigError`. */
|
|
8
|
+
function resolvePlan(options = {}) {
|
|
9
|
+
const layer = options.layer ?? "vendor";
|
|
10
|
+
if (!LAYER_NAME.test(layer)) throw new LayergateConfigError(`layer "${layer}" is not a layer name`);
|
|
11
|
+
const order = options.order ?? [layer];
|
|
12
|
+
for (const name of order) if (!LAYER_NAME.test(name)) throw new LayergateConfigError(`order: "${name}" is not a layer name`);
|
|
13
|
+
const duplicate = order.find((name, index) => order.indexOf(name) !== index);
|
|
14
|
+
if (duplicate) throw new LayergateConfigError(`order: "${duplicate}" appears twice`);
|
|
15
|
+
if (!order.includes(layer)) throw new LayergateConfigError(`order must include the quarantine layer "${layer}"`);
|
|
16
|
+
const optOut = options.optOut ?? [];
|
|
17
|
+
const glob = optOut.find((entry) => /[*?[\]{}]/.test(entry));
|
|
18
|
+
if (glob) throw new LayergateConfigError(`optOut: "${glob}" is a pattern; list exact files`);
|
|
19
|
+
const dependencies = options.dependencies ?? false;
|
|
20
|
+
return {
|
|
21
|
+
layer,
|
|
22
|
+
order,
|
|
23
|
+
sheets: options.sheets ?? [],
|
|
24
|
+
dependencies: dependencies === true || dependencies === false ? dependencies : new Set(dependencies),
|
|
25
|
+
optOut
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
Object.defineProperty(exports, "LayergateConfigError", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function() {
|
|
32
|
+
return LayergateConfigError;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(exports, "resolvePlan", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
get: function() {
|
|
38
|
+
return resolvePlan;
|
|
39
|
+
}
|
|
40
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/plan.d.ts
|
|
2
|
+
/** What layergate owns and how it layers it, as configured. */
|
|
3
|
+
interface LayergateOptions {
|
|
4
|
+
/** The cascade layer each owned stylesheet's own rules go into. Default
|
|
5
|
+
* `vendor`. */
|
|
6
|
+
layer?: string;
|
|
7
|
+
/** The full layer order every finished stylesheet declares first; it must
|
|
8
|
+
* include `layer`. Default: `[layer]`. */
|
|
9
|
+
order?: readonly string[];
|
|
10
|
+
/** Stylesheets `virtual:layergate` delivers, in this order, whether or
|
|
11
|
+
* not anything else imports them: package specifiers or paths relative
|
|
12
|
+
* to the Vite root. */
|
|
13
|
+
sheets?: readonly string[];
|
|
14
|
+
/** Also own `.css` a JS module imports from a package other than the app:
|
|
15
|
+
* `true` for every package, or the package names. Default: none. */
|
|
16
|
+
dependencies?: boolean | readonly string[];
|
|
17
|
+
/** Files inside an owned graph whose own rules stay outside the layer:
|
|
18
|
+
* exact package specifiers or paths, never globs. */
|
|
19
|
+
optOut?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
interface LayergatePlan {
|
|
22
|
+
layer: string;
|
|
23
|
+
order: readonly string[];
|
|
24
|
+
sheets: readonly string[];
|
|
25
|
+
dependencies: boolean | ReadonlySet<string>;
|
|
26
|
+
optOut: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
declare class LayergateConfigError extends Error {
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
/** The plan `options` describe, or a `LayergateConfigError`. */
|
|
32
|
+
declare function resolvePlan(options?: LayergateOptions): LayergatePlan;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolvePlan as i, LayergateOptions as n, LayergatePlan as r, LayergateConfigError as t };
|
|
35
|
+
//# sourceMappingURL=plan-w-y0limy.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-w-y0limy.d.cts","names":[],"sources":["../src/plan.ts"],"mappings":";;UACiB;;;EAGf;;;EAGA;;;;EAIA;;;EAGA;;;EAGA;;UAGe;EACf;EACA;EACA;EACA,wBAAwB;EACxB;;cAMW,6BAA6B;EAC/B;;;iBAIK,YAAY,UAAS,mBAAwB"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
//#region src/plan.d.ts
|
|
2
|
+
/** What layergate owns and how it layers it, as configured. */
|
|
3
|
+
interface LayergateOptions {
|
|
4
|
+
/** The cascade layer each owned stylesheet's own rules go into. Default
|
|
5
|
+
* `vendor`. */
|
|
6
|
+
layer?: string;
|
|
7
|
+
/** The full layer order every finished stylesheet declares first; it must
|
|
8
|
+
* include `layer`. Default: `[layer]`. */
|
|
9
|
+
order?: readonly string[];
|
|
10
|
+
/** Stylesheets `virtual:layergate` delivers, in this order, whether or
|
|
11
|
+
* not anything else imports them: package specifiers or paths relative
|
|
12
|
+
* to the Vite root. */
|
|
13
|
+
sheets?: readonly string[];
|
|
14
|
+
/** Also own `.css` a JS module imports from a package other than the app:
|
|
15
|
+
* `true` for every package, or the package names. Default: none. */
|
|
16
|
+
dependencies?: boolean | readonly string[];
|
|
17
|
+
/** Files inside an owned graph whose own rules stay outside the layer:
|
|
18
|
+
* exact package specifiers or paths, never globs. */
|
|
19
|
+
optOut?: readonly string[];
|
|
20
|
+
}
|
|
21
|
+
interface LayergatePlan {
|
|
22
|
+
layer: string;
|
|
23
|
+
order: readonly string[];
|
|
24
|
+
sheets: readonly string[];
|
|
25
|
+
dependencies: boolean | ReadonlySet<string>;
|
|
26
|
+
optOut: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
declare class LayergateConfigError extends Error {
|
|
29
|
+
name: string;
|
|
30
|
+
}
|
|
31
|
+
/** The plan `options` describe, or a `LayergateConfigError`. */
|
|
32
|
+
declare function resolvePlan(options?: LayergateOptions): LayergatePlan;
|
|
33
|
+
//#endregion
|
|
34
|
+
export { resolvePlan as i, LayergateOptions as n, LayergatePlan as r, LayergateConfigError as t };
|
|
35
|
+
//# sourceMappingURL=plan-w-y0limy.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plan-w-y0limy.d.mts","names":[],"sources":["../src/plan.ts"],"mappings":";;UACiB;;;EAGf;;;EAGA;;;;EAIA;;;EAGA;;;EAGA;;UAGe;EACf;EACA;EACA;EACA,wBAAwB;EACxB;;cAMW,6BAA6B;EAC/B;;;iBAIK,YAAY,UAAS,mBAAwB"}
|