@typestyles/rollup 0.5.8 → 0.6.0
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 +65 -22
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +66 -23
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5,41 +5,84 @@ Object.defineProperties(exports, {
|
|
|
5
5
|
let _typestyles_build_runner = require("@typestyles/build-runner");
|
|
6
6
|
//#region src/index.ts
|
|
7
7
|
function typestylesRollupPlugin(options = {}) {
|
|
8
|
-
const { warnDuplicates = true, extract, root = process.cwd() } = options;
|
|
8
|
+
const { warnDuplicates = true, extract, root = process.cwd(), compile = false } = options;
|
|
9
9
|
const moduleNamespaces = new Map();
|
|
10
10
|
let resolvedExtractModules = [];
|
|
11
11
|
let resolvedMode = "runtime";
|
|
12
|
+
let extraction = null;
|
|
13
|
+
let planIndex = null;
|
|
14
|
+
const extractOnce = () => extraction ??= (0, _typestyles_build_runner.runTypestylesExtract)({
|
|
15
|
+
root,
|
|
16
|
+
modules: resolvedExtractModules
|
|
17
|
+
});
|
|
18
|
+
const compileEnabled = () => compile && resolvedMode === "build" && resolvedExtractModules.length > 0;
|
|
19
|
+
function finishTransform(source, id, compiled) {
|
|
20
|
+
const code = compiled?.code ?? source;
|
|
21
|
+
if ((resolvedMode === "build" || resolvedMode === "hybrid") && code.includes("__TYPESTYLES_RUNTIME_DISABLED__")) return {
|
|
22
|
+
code: code.replace(/__TYPESTYLES_RUNTIME_DISABLED__/g, "\"true\""),
|
|
23
|
+
map: compiled?.map ?? null
|
|
24
|
+
};
|
|
25
|
+
trackNamespaces.call(this, source, id);
|
|
26
|
+
return compiled ? {
|
|
27
|
+
code: compiled.code,
|
|
28
|
+
map: compiled.map
|
|
29
|
+
} : null;
|
|
30
|
+
}
|
|
31
|
+
function trackNamespaces(code, id) {
|
|
32
|
+
if (!/\.[jt]sx?$/.test(id)) return;
|
|
33
|
+
if (id.includes("node_modules")) return;
|
|
34
|
+
if (!_typestyles_build_runner.TYPESTYLES_IMPORT_RE.test(code)) return;
|
|
35
|
+
const { keys, prefixes } = (0, _typestyles_build_runner.extractNamespaces)(code);
|
|
36
|
+
if (keys.length === 0 && prefixes.length === 0) return;
|
|
37
|
+
if (warnDuplicates) (0, _typestyles_build_runner.reportDuplicateNamespaces)(moduleNamespaces, id, prefixes, this);
|
|
38
|
+
moduleNamespaces.set(id, {
|
|
39
|
+
keys,
|
|
40
|
+
prefixes
|
|
41
|
+
});
|
|
42
|
+
}
|
|
12
43
|
return {
|
|
13
44
|
name: "typestyles-rollup",
|
|
14
|
-
buildStart() {
|
|
45
|
+
async buildStart() {
|
|
15
46
|
resolvedExtractModules = (0, _typestyles_build_runner.resolveExtractModules)(root, extract);
|
|
16
47
|
resolvedMode = (0, _typestyles_build_runner.resolveExtractMode)(options.mode, resolvedExtractModules);
|
|
48
|
+
extraction = null;
|
|
49
|
+
planIndex = null;
|
|
50
|
+
if (compileEnabled()) await extractOnce();
|
|
51
|
+
},
|
|
52
|
+
async resolveId(source, importer) {
|
|
53
|
+
if (resolvedMode !== "build" || !(0, _typestyles_build_runner.isSheetRequest)(source)) return null;
|
|
54
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
55
|
+
if (!resolved) return null;
|
|
56
|
+
const noop = (0, _typestyles_build_runner.toZeroRuntimeSheetId)(resolved.id);
|
|
57
|
+
return noop ? {
|
|
58
|
+
...resolved,
|
|
59
|
+
id: noop
|
|
60
|
+
} : null;
|
|
17
61
|
},
|
|
18
|
-
transform(
|
|
19
|
-
if ((
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
if (id.includes("node_modules")) return null;
|
|
25
|
-
if (!_typestyles_build_runner.TYPESTYLES_IMPORT_RE.test(code)) return null;
|
|
26
|
-
const { keys, prefixes } = (0, _typestyles_build_runner.extractNamespaces)(code);
|
|
27
|
-
if (keys.length === 0 && prefixes.length === 0) return null;
|
|
28
|
-
if (warnDuplicates) (0, _typestyles_build_runner.reportDuplicateNamespaces)(moduleNamespaces, id, prefixes, this);
|
|
29
|
-
moduleNamespaces.set(id, {
|
|
30
|
-
keys,
|
|
31
|
-
prefixes
|
|
62
|
+
transform(source, id) {
|
|
63
|
+
if (!(compileEnabled() && (0, _typestyles_build_runner.isTransformableId)(id))) return finishTransform.call(this, source, id, null);
|
|
64
|
+
return extractOnce().then(({ plans }) => {
|
|
65
|
+
planIndex ??= (0, _typestyles_build_runner.indexPlans)(plans);
|
|
66
|
+
const compiled = (0, _typestyles_build_runner.transformRecipeCalls)(source, planIndex, (text) => this.parse(text), id);
|
|
67
|
+
return finishTransform.call(this, source, id, compiled);
|
|
32
68
|
});
|
|
33
|
-
return null;
|
|
34
69
|
},
|
|
35
|
-
|
|
70
|
+
shouldTransformCachedModule({ code }) {
|
|
71
|
+
return compileEnabled() && (0, _typestyles_build_runner.mayNeedRecompile)(code);
|
|
72
|
+
},
|
|
73
|
+
async generateBundle(_options, bundle) {
|
|
74
|
+
if (resolvedMode === "build") {
|
|
75
|
+
const leaked = (0, _typestyles_build_runner.findRealSheetModules)(Object.values(bundle ?? {}).flatMap((chunk) => chunk.type === "chunk" ? Object.keys(chunk.modules) : []));
|
|
76
|
+
if (leaked.length > 0) this.warn((0, _typestyles_build_runner.zeroRuntimeLeakMessage)(leaked));
|
|
77
|
+
if (compileEnabled()) {
|
|
78
|
+
const warning = (0, _typestyles_build_runner.lingeringRuntimeWarning)(bundle ?? {}, (id) => this.getModuleInfo(id)?.importers, root);
|
|
79
|
+
if (warning) this.warn(warning);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
36
82
|
if (resolvedMode === "runtime") return;
|
|
37
83
|
if (!resolvedExtractModules.length) return;
|
|
38
84
|
try {
|
|
39
|
-
const css = await (
|
|
40
|
-
root,
|
|
41
|
-
modules: resolvedExtractModules
|
|
42
|
-
});
|
|
85
|
+
const { css } = await extractOnce();
|
|
43
86
|
this.emitFile({
|
|
44
87
|
type: "asset",
|
|
45
88
|
fileName: extract?.fileName ?? "typestyles.css",
|
package/dist/index.d.cts
CHANGED
|
@@ -29,6 +29,13 @@ export interface TypestylesRollupPluginOptions {
|
|
|
29
29
|
* Defaults to `process.cwd()`.
|
|
30
30
|
*/
|
|
31
31
|
root?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Experimental. In `"build"` mode, replace `recipe()` definitions with the small call-behavior
|
|
34
|
+
* plans recorded during extraction, so style configs and CSS machinery tree-shake out of the
|
|
35
|
+
* bundle. Rollup applies `transform` hooks in plugin order, so list this plugin **after** any
|
|
36
|
+
* TypeScript/JSX plugin: only plain-JS modules are rewritten.
|
|
37
|
+
*/
|
|
38
|
+
compile?: boolean;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Rollup plugin for typestyles runtime + optional static extraction.
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,13 @@ export interface TypestylesRollupPluginOptions {
|
|
|
29
29
|
* Defaults to `process.cwd()`.
|
|
30
30
|
*/
|
|
31
31
|
root?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Experimental. In `"build"` mode, replace `recipe()` definitions with the small call-behavior
|
|
34
|
+
* plans recorded during extraction, so style configs and CSS machinery tree-shake out of the
|
|
35
|
+
* bundle. Rollup applies `transform` hooks in plugin order, so list this plugin **after** any
|
|
36
|
+
* TypeScript/JSX plugin: only plain-JS modules are rewritten.
|
|
37
|
+
*/
|
|
38
|
+
compile?: boolean;
|
|
32
39
|
}
|
|
33
40
|
/**
|
|
34
41
|
* Rollup plugin for typestyles runtime + optional static extraction.
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,84 @@
|
|
|
1
|
-
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, TYPESTYLES_IMPORT_RE, discoverDefaultExtractModules, extractNamespaces, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules,
|
|
1
|
+
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, TYPESTYLES_IMPORT_RE, discoverDefaultExtractModules, extractNamespaces, findRealSheetModules, indexPlans, isSheetRequest, isTransformableId, lingeringRuntimeWarning, mayNeedRecompile, reportDuplicateNamespaces, resolveExtractMode, resolveExtractModules, runTypestylesExtract, toZeroRuntimeSheetId, transformRecipeCalls, zeroRuntimeLeakMessage } from "@typestyles/build-runner";
|
|
2
2
|
//#region src/index.ts
|
|
3
3
|
function typestylesRollupPlugin(options = {}) {
|
|
4
|
-
const { warnDuplicates = true, extract, root = process.cwd() } = options;
|
|
4
|
+
const { warnDuplicates = true, extract, root = process.cwd(), compile = false } = options;
|
|
5
5
|
const moduleNamespaces = new Map();
|
|
6
6
|
let resolvedExtractModules = [];
|
|
7
7
|
let resolvedMode = "runtime";
|
|
8
|
+
let extraction = null;
|
|
9
|
+
let planIndex = null;
|
|
10
|
+
const extractOnce = () => extraction ??= runTypestylesExtract({
|
|
11
|
+
root,
|
|
12
|
+
modules: resolvedExtractModules
|
|
13
|
+
});
|
|
14
|
+
const compileEnabled = () => compile && resolvedMode === "build" && resolvedExtractModules.length > 0;
|
|
15
|
+
function finishTransform(source, id, compiled) {
|
|
16
|
+
const code = compiled?.code ?? source;
|
|
17
|
+
if ((resolvedMode === "build" || resolvedMode === "hybrid") && code.includes("__TYPESTYLES_RUNTIME_DISABLED__")) return {
|
|
18
|
+
code: code.replace(/__TYPESTYLES_RUNTIME_DISABLED__/g, "\"true\""),
|
|
19
|
+
map: compiled?.map ?? null
|
|
20
|
+
};
|
|
21
|
+
trackNamespaces.call(this, source, id);
|
|
22
|
+
return compiled ? {
|
|
23
|
+
code: compiled.code,
|
|
24
|
+
map: compiled.map
|
|
25
|
+
} : null;
|
|
26
|
+
}
|
|
27
|
+
function trackNamespaces(code, id) {
|
|
28
|
+
if (!/\.[jt]sx?$/.test(id)) return;
|
|
29
|
+
if (id.includes("node_modules")) return;
|
|
30
|
+
if (!TYPESTYLES_IMPORT_RE.test(code)) return;
|
|
31
|
+
const { keys, prefixes } = extractNamespaces(code);
|
|
32
|
+
if (keys.length === 0 && prefixes.length === 0) return;
|
|
33
|
+
if (warnDuplicates) reportDuplicateNamespaces(moduleNamespaces, id, prefixes, this);
|
|
34
|
+
moduleNamespaces.set(id, {
|
|
35
|
+
keys,
|
|
36
|
+
prefixes
|
|
37
|
+
});
|
|
38
|
+
}
|
|
8
39
|
return {
|
|
9
40
|
name: "typestyles-rollup",
|
|
10
|
-
buildStart() {
|
|
41
|
+
async buildStart() {
|
|
11
42
|
resolvedExtractModules = resolveExtractModules(root, extract);
|
|
12
43
|
resolvedMode = resolveExtractMode(options.mode, resolvedExtractModules);
|
|
44
|
+
extraction = null;
|
|
45
|
+
planIndex = null;
|
|
46
|
+
if (compileEnabled()) await extractOnce();
|
|
13
47
|
},
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
48
|
+
async resolveId(source, importer) {
|
|
49
|
+
if (resolvedMode !== "build" || !isSheetRequest(source)) return null;
|
|
50
|
+
const resolved = await this.resolve(source, importer, { skipSelf: true });
|
|
51
|
+
if (!resolved) return null;
|
|
52
|
+
const noop = toZeroRuntimeSheetId(resolved.id);
|
|
53
|
+
return noop ? {
|
|
54
|
+
...resolved,
|
|
55
|
+
id: noop
|
|
56
|
+
} : null;
|
|
57
|
+
},
|
|
58
|
+
transform(source, id) {
|
|
59
|
+
if (!(compileEnabled() && isTransformableId(id))) return finishTransform.call(this, source, id, null);
|
|
60
|
+
return extractOnce().then(({ plans }) => {
|
|
61
|
+
planIndex ??= indexPlans(plans);
|
|
62
|
+
const compiled = transformRecipeCalls(source, planIndex, (text) => this.parse(text), id);
|
|
63
|
+
return finishTransform.call(this, source, id, compiled);
|
|
28
64
|
});
|
|
29
|
-
return null;
|
|
30
65
|
},
|
|
31
|
-
|
|
66
|
+
shouldTransformCachedModule({ code }) {
|
|
67
|
+
return compileEnabled() && mayNeedRecompile(code);
|
|
68
|
+
},
|
|
69
|
+
async generateBundle(_options, bundle) {
|
|
70
|
+
if (resolvedMode === "build") {
|
|
71
|
+
const leaked = findRealSheetModules(Object.values(bundle ?? {}).flatMap((chunk) => chunk.type === "chunk" ? Object.keys(chunk.modules) : []));
|
|
72
|
+
if (leaked.length > 0) this.warn(zeroRuntimeLeakMessage(leaked));
|
|
73
|
+
if (compileEnabled()) {
|
|
74
|
+
const warning = lingeringRuntimeWarning(bundle ?? {}, (id) => this.getModuleInfo(id)?.importers, root);
|
|
75
|
+
if (warning) this.warn(warning);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
32
78
|
if (resolvedMode === "runtime") return;
|
|
33
79
|
if (!resolvedExtractModules.length) return;
|
|
34
80
|
try {
|
|
35
|
-
const css = await
|
|
36
|
-
root,
|
|
37
|
-
modules: resolvedExtractModules
|
|
38
|
-
});
|
|
81
|
+
const { css } = await extractOnce();
|
|
39
82
|
this.emitFile({
|
|
40
83
|
type: "asset",
|
|
41
84
|
fileName: extract?.fileName ?? "typestyles.css",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/rollup",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "Rollup and Rolldown plugin for typestyles",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"rollup": ">=4.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@typestyles/build-runner": "0.
|
|
41
|
+
"@typestyles/build-runner": "0.8.0"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/node": "^24.13.0",
|