@master/css-vite 0.0.0-site.1793659883.g69c9aebcf628

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.
Files changed (121) hide show
  1. package/README.md +348 -0
  2. package/dist/common.d.ts +14 -0
  3. package/dist/common.js +26 -0
  4. package/dist/core.d.ts +23 -0
  5. package/dist/core.js +165 -0
  6. package/dist/index.d.ts +3 -0
  7. package/dist/index.js +1 -0
  8. package/dist/internal/src/emitted-globals-module.js +12 -0
  9. package/dist/internal/src/manifest-facade.js +68 -0
  10. package/dist/internal/src/manifest-loader.js +33 -0
  11. package/dist/internal/src/manifest-module.js +58 -0
  12. package/dist/internal/src/manifest-virtual-module.js +123 -0
  13. package/dist/internal/src/node.js +22 -0
  14. package/dist/internal/src/program-module.js +50 -0
  15. package/dist/internal/src/project.js +10 -0
  16. package/dist/internal/src/runtime-bootstrap.js +80 -0
  17. package/dist/internal/src/style-module.js +3 -0
  18. package/dist/modes/pre-render.d.ts +5 -0
  19. package/dist/modes/pre-render.js +6 -0
  20. package/dist/modes/progressive.d.ts +5 -0
  21. package/dist/modes/progressive.js +12 -0
  22. package/dist/modes/runtime.d.ts +5 -0
  23. package/dist/modes/runtime.js +17 -0
  24. package/dist/modes/static.d.ts +5 -0
  25. package/dist/modes/static.js +5 -0
  26. package/dist/options.d.ts +20 -0
  27. package/dist/options.js +23 -0
  28. package/dist/plugins/avoid-fouc.d.ts +5 -0
  29. package/dist/plugins/avoid-fouc.js +48 -0
  30. package/dist/plugins/build-stylesheet-recovery.d.ts +5 -0
  31. package/dist/plugins/build-stylesheet-recovery.js +26 -0
  32. package/dist/plugins/context.d.ts +5 -0
  33. package/dist/plugins/context.js +12 -0
  34. package/dist/plugins/dev-stylesheet.d.ts +4 -0
  35. package/dist/plugins/dev-stylesheet.js +63 -0
  36. package/dist/plugins/emitted-globals-virtual-module.d.ts +14 -0
  37. package/dist/plugins/emitted-globals-virtual-module.js +167 -0
  38. package/dist/plugins/inject-runtime.d.ts +5 -0
  39. package/dist/plugins/inject-runtime.js +51 -0
  40. package/dist/plugins/inline-stylesheet.d.ts +5 -0
  41. package/dist/plugins/inline-stylesheet.js +197 -0
  42. package/dist/plugins/local-styles.d.ts +5 -0
  43. package/dist/plugins/local-styles.js +214 -0
  44. package/dist/plugins/manifest-loader.d.ts +4 -0
  45. package/dist/plugins/manifest-loader.js +102 -0
  46. package/dist/plugins/manifest-virtual-module.d.ts +4 -0
  47. package/dist/plugins/manifest-virtual-module.js +70 -0
  48. package/dist/plugins/pre-render.d.ts +5 -0
  49. package/dist/plugins/pre-render.js +224 -0
  50. package/dist/plugins/program-preload.d.ts +5 -0
  51. package/dist/plugins/program-preload.js +37 -0
  52. package/dist/plugins/runtime-bootstrap.d.ts +3 -0
  53. package/dist/plugins/runtime-bootstrap.js +14 -0
  54. package/dist/plugins/runtime-preload.d.ts +4 -0
  55. package/dist/plugins/runtime-preload.js +38 -0
  56. package/dist/plugins/sass-source.d.ts +5 -0
  57. package/dist/plugins/sass-source.js +176 -0
  58. package/dist/plugins/scanner.d.ts +5 -0
  59. package/dist/plugins/scanner.js +24 -0
  60. package/dist/plugins/style-entry-build.d.ts +5 -0
  61. package/dist/plugins/style-entry-build.js +121 -0
  62. package/dist/plugins/style-entry-hmr.d.ts +6 -0
  63. package/dist/plugins/style-entry-hmr.js +78 -0
  64. package/dist/plugins/style-entry.d.ts +5 -0
  65. package/dist/plugins/style-entry.js +89 -0
  66. package/dist/plugins/stylesheet-recovery.d.ts +5 -0
  67. package/dist/plugins/stylesheet-recovery.js +70 -0
  68. package/dist/plugins/usage-graph.d.ts +5 -0
  69. package/dist/plugins/usage-graph.js +48 -0
  70. package/dist/preset/src/default-manifest.js +15913 -0
  71. package/dist/utils/build-import-resolver.d.ts +29 -0
  72. package/dist/utils/build-import-resolver.js +101 -0
  73. package/dist/utils/build-sass-source.d.ts +38 -0
  74. package/dist/utils/build-sass-source.js +225 -0
  75. package/dist/utils/build-stylesheet-delivery.d.ts +12 -0
  76. package/dist/utils/build-stylesheet-delivery.js +130 -0
  77. package/dist/utils/build-watch-recovery.d.ts +10 -0
  78. package/dist/utils/build-watch-recovery.js +119 -0
  79. package/dist/utils/coalesced-task.d.ts +3 -0
  80. package/dist/utils/coalesced-task.js +25 -0
  81. package/dist/utils/dev-module-refresh.d.ts +9 -0
  82. package/dist/utils/dev-module-refresh.js +17 -0
  83. package/dist/utils/dev-stylesheet-delivery.d.ts +21 -0
  84. package/dist/utils/dev-stylesheet-delivery.js +98 -0
  85. package/dist/utils/environment-closing.d.ts +3 -0
  86. package/dist/utils/environment-closing.js +28 -0
  87. package/dist/utils/extracted-css.d.ts +4 -0
  88. package/dist/utils/extracted-css.js +34 -0
  89. package/dist/utils/failed-dependency-reconciliation.d.ts +15 -0
  90. package/dist/utils/failed-dependency-reconciliation.js +150 -0
  91. package/dist/utils/failed-stylesheet-dependencies.d.ts +16 -0
  92. package/dist/utils/failed-stylesheet-dependencies.js +92 -0
  93. package/dist/utils/html.d.ts +8 -0
  94. package/dist/utils/html.js +36 -0
  95. package/dist/utils/inline-stylesheet.d.ts +37 -0
  96. package/dist/utils/inline-stylesheet.js +129 -0
  97. package/dist/utils/local-stylesheet.d.ts +10 -0
  98. package/dist/utils/local-stylesheet.js +25 -0
  99. package/dist/utils/manifest-recovery.d.ts +11 -0
  100. package/dist/utils/manifest-recovery.js +77 -0
  101. package/dist/utils/module-sources.d.ts +26 -0
  102. package/dist/utils/module-sources.js +131 -0
  103. package/dist/utils/path.d.ts +5 -0
  104. package/dist/utils/path.js +27 -0
  105. package/dist/utils/recovery-error.d.ts +3 -0
  106. package/dist/utils/recovery-error.js +17 -0
  107. package/dist/utils/register-style-source.d.ts +4 -0
  108. package/dist/utils/register-style-source.js +23 -0
  109. package/dist/utils/sass-diagnostics.d.ts +4 -0
  110. package/dist/utils/sass-diagnostics.js +109 -0
  111. package/dist/utils/sass-proxy-access.d.ts +4 -0
  112. package/dist/utils/sass-proxy-access.js +28 -0
  113. package/dist/utils/sass-source-markers.d.ts +8 -0
  114. package/dist/utils/sass-source-markers.js +50 -0
  115. package/dist/utils/scanner-context.d.ts +12 -0
  116. package/dist/utils/scanner-context.js +100 -0
  117. package/dist/utils/scoped-plugins.d.ts +4 -0
  118. package/dist/utils/scoped-plugins.js +81 -0
  119. package/dist/utils/write-file.d.ts +3 -0
  120. package/dist/utils/write-file.js +9 -0
  121. package/package.json +62 -0
@@ -0,0 +1,50 @@
1
+ import { createHash } from "node:crypto";
2
+ import MagicString from "magic-string";
3
+ // src/utils/sass-source-markers.ts
4
+ /** Keep input identities visible through Sass and Vite's source-map chaining. */
5
+ function createSassSourceMarkers(onSource) {
6
+ const markers = /* @__PURE__ */ new Set();
7
+ return {
8
+ markers,
9
+ additionalData(value) {
10
+ return async (source, id) => {
11
+ onSource?.(id, source);
12
+ const marker = `!master-css:module-input-${createHash("sha256").update(id).digest("hex")}`;
13
+ markers.add(marker);
14
+ const suffix = `\n/*${marker}*/`;
15
+ if (typeof value === "function") {
16
+ const result = await value(source, id);
17
+ if (result === source) {
18
+ const edited = new MagicString(source).append(suffix);
19
+ return {
20
+ content: edited.toString(),
21
+ map: edited.generateMap({
22
+ hires: "boundary",
23
+ source: id,
24
+ file: id,
25
+ includeContent: true
26
+ })
27
+ };
28
+ }
29
+ return typeof result === "string" ? result + suffix : {
30
+ ...result,
31
+ content: result.content + suffix
32
+ };
33
+ }
34
+ const edited = new MagicString(source);
35
+ if (value) edited.prepend(value);
36
+ edited.append(suffix);
37
+ return {
38
+ content: edited.toString(),
39
+ map: edited.generateMap({
40
+ hires: "boundary",
41
+ source: id,
42
+ file: id,
43
+ includeContent: true
44
+ })
45
+ };
46
+ };
47
+ }
48
+ };
49
+ }
50
+ export { createSassSourceMarkers };
@@ -0,0 +1,12 @@
1
+ import { ResolvedConfig } from "vite";
2
+ import { MasterCSSScanner } from "@master/css-tooling/scanner/node";
3
+ import { ResolvedMasterCSSVitePluginOptions } from "../options.js";
4
+ import { MasterCSSVitePluginContext } from "../core.js";
5
+ declare function getScanner(context: MasterCSSVitePluginContext): MasterCSSScanner;
6
+ declare function ensureScanner(options: ResolvedMasterCSSVitePluginOptions, context: MasterCSSVitePluginContext): Promise<MasterCSSScanner>;
7
+ /** Observe the public server registry, including idle replacement environments. */
8
+ declare function trackScannerEnvironments(context: MasterCSSVitePluginContext, config: ResolvedConfig, getEnvironments: () => Iterable<object>): void;
9
+ /** Both scanner and HMR cleanup may release the same environment; deletion is idempotent. */
10
+ declare function releaseScannerEnvironment(context: MasterCSSVitePluginContext, config: ResolvedConfig | undefined, environment?: object): boolean;
11
+ declare function disposeScanner(context: MasterCSSVitePluginContext, config?: ResolvedConfig | undefined): Promise<void>;
12
+ export { disposeScanner, ensureScanner, getScanner, releaseScannerEnvironment, trackScannerEnvironments };
@@ -0,0 +1,100 @@
1
+ import { defaultBuildManifest } from "../internal/src/project.js";
2
+ import { MasterCSSScanner } from "@master/css-tooling/scanner/node";
3
+ // src/utils/scanner-context.ts
4
+ function getScanner(context) {
5
+ if (!context.scanner) throw new Error("[@master/css-vite] Scanner context was not initialized.");
6
+ return context.scanner;
7
+ }
8
+ const scannerStates = /* @__PURE__ */ new WeakMap();
9
+ const currentStates = /* @__PURE__ */ new WeakMap();
10
+ async function ensureScanner(options, context) {
11
+ const config = context.config;
12
+ if (!config) throw new Error("[@master/css-vite] Cannot initialize the scanner before Vite config is resolved.");
13
+ let states = scannerStates.get(context);
14
+ if (!states) {
15
+ states = /* @__PURE__ */ new WeakMap();
16
+ scannerStates.set(context, states);
17
+ }
18
+ let state = states.get(config);
19
+ if (state?.disposing) {
20
+ await state.disposing;
21
+ return ensureScanner(options, context);
22
+ }
23
+ if (!state) {
24
+ const previous = currentStates.get(context);
25
+ if (previous) previous.stylesheets = context.stylesheets;
26
+ context.scanner = void 0;
27
+ context.stylesheets = void 0;
28
+ state = {};
29
+ states.set(config, state);
30
+ currentStates.set(context, state);
31
+ }
32
+ if (state.scanner) return state.scanner;
33
+ if (state.initializing) return state.initializing;
34
+ const owner = state;
35
+ const scanner = new MasterCSSScanner({
36
+ manifest: defaultBuildManifest,
37
+ ...options.scanner,
38
+ outputDirectories: [...options.scanner?.outputDirectories ?? [], ...config.build?.outDir ? [config.build.outDir] : []]
39
+ }, config.root);
40
+ owner.initializing = scanner.init().then(() => {
41
+ scanner.options.verbose = 0;
42
+ owner.scanner = scanner;
43
+ if (currentStates.get(context) === owner && !owner.disposing) context.scanner = scanner;
44
+ return scanner;
45
+ }).catch(async (error) => {
46
+ await scanner.dispose();
47
+ if (states.get(config) === owner) states.delete(config);
48
+ throw error;
49
+ }).finally(() => {
50
+ owner.initializing = void 0;
51
+ });
52
+ return owner.initializing;
53
+ }
54
+ /** Observe the public server registry, including idle replacement environments. */
55
+ function trackScannerEnvironments(context, config, getEnvironments) {
56
+ const owner = scannerStates.get(context)?.get(config);
57
+ if (owner) {
58
+ owner.environments = new Set(getEnvironments());
59
+ owner.closedEnvironments = /* @__PURE__ */ new WeakSet();
60
+ owner.getEnvironments = getEnvironments;
61
+ }
62
+ }
63
+ /** Both scanner and HMR cleanup may release the same environment; deletion is idempotent. */
64
+ function releaseScannerEnvironment(context, config, environment) {
65
+ const owner = config && scannerStates.get(context)?.get(config);
66
+ if (!environment || !owner?.environments) return true;
67
+ owner.closedEnvironments?.add(environment);
68
+ for (const current of owner.getEnvironments?.() ?? []) if (!owner.closedEnvironments?.has(current)) owner.environments.add(current);
69
+ owner.environments.delete(environment);
70
+ return owner.environments.size === 0;
71
+ }
72
+ async function disposeScanner(context, config = context.config) {
73
+ if (!config) return;
74
+ const states = scannerStates.get(context), owner = states?.get(config);
75
+ if (!owner) return;
76
+ if (owner.disposing) return owner.disposing;
77
+ if (currentStates.get(context) === owner) {
78
+ owner.stylesheets = context.stylesheets;
79
+ context.scanner = void 0;
80
+ context.stylesheets = void 0;
81
+ currentStates.delete(context);
82
+ }
83
+ owner.disposing = (async () => {
84
+ try {
85
+ await owner.initializing;
86
+ } catch {}
87
+ const scanner = owner.scanner;
88
+ owner.scanner = void 0;
89
+ try {
90
+ await scanner?.dispose();
91
+ } finally {
92
+ owner.stylesheets?.dispose();
93
+ owner.stylesheets = void 0;
94
+ }
95
+ })().finally(() => {
96
+ if (states?.get(config) === owner) states.delete(config);
97
+ });
98
+ return owner.disposing;
99
+ }
100
+ export { disposeScanner, ensureScanner, getScanner, releaseScannerEnvironment, trackScannerEnvironments };
@@ -0,0 +1,4 @@
1
+ import { Plugin } from "vite";
2
+ /** Keep every plugin's closures together within one Vite resolved configuration. */
3
+ declare function scopePlugins(createPlugins: () => Plugin[]): Plugin[];
4
+ export { scopePlugins };
@@ -0,0 +1,81 @@
1
+ import { AsyncLocalStorage } from "node:async_hooks";
2
+ // src/utils/scoped-plugins.ts
3
+ /** Vite runs these on the top-level plugin and ignores them on environment plugins. */
4
+ const topLevelHooks = /* @__PURE__ */ new Set([
5
+ "apply",
6
+ "applyToEnvironment",
7
+ "config",
8
+ "configEnvironment",
9
+ "configResolved",
10
+ "configureServer",
11
+ "configurePreviewServer"
12
+ ]);
13
+ function hookConfig(name, receiver, args) {
14
+ if (name === "configResolved") return args[0];
15
+ if (name === "configureServer" || name === "configurePreviewServer") return args[0].config;
16
+ if (name === "applyToEnvironment") return args[0].getTopLevelConfig();
17
+ if (name === "handleHotUpdate") return args[0].server?.config;
18
+ if (name === "transformIndexHtml") {
19
+ const server = args[1]?.server;
20
+ if (server) return server.config;
21
+ }
22
+ return receiver?.environment?.getTopLevelConfig();
23
+ }
24
+ /** Keep every plugin's closures together within one Vite resolved configuration. */
25
+ function scopePlugins(createPlugins) {
26
+ const invocationConfig = new AsyncLocalStorage();
27
+ const templates = createPlugins();
28
+ const configurations = /* @__PURE__ */ new WeakMap();
29
+ let initialized = false;
30
+ let shared = false;
31
+ const forConfig = (config) => {
32
+ let plugins = configurations.get(config);
33
+ if (!plugins) {
34
+ shared ||= initialized;
35
+ plugins = initialized ? createPlugins() : templates;
36
+ initialized = true;
37
+ configurations.set(config, plugins);
38
+ }
39
+ return plugins;
40
+ };
41
+ return templates.map((template, index) => {
42
+ const plugin = { ...template };
43
+ for (const [name, hook] of Object.entries(template)) {
44
+ if (name === "apply" || name === "config" || name === "configEnvironment") continue;
45
+ if (typeof (typeof hook === "function" ? hook : hook && typeof hook === "object" && "handler" in hook ? hook.handler : void 0) !== "function") continue;
46
+ const invoke = function(...args) {
47
+ const config = hookConfig(name, this, args) ?? invocationConfig.getStore();
48
+ if (!config && shared) throw new Error(`Master CSS ${name} requires a Vite environment or server when plugins are shared`);
49
+ const selected = (config ? forConfig(config)[index] : template)[name];
50
+ return (typeof selected === "function" ? selected : selected.handler).apply(this, args);
51
+ };
52
+ plugin[name] = typeof hook === "function" ? invoke : {
53
+ ...hook,
54
+ handler: invoke
55
+ };
56
+ }
57
+ plugin.applyToEnvironment = async (environment) => {
58
+ const config = environment.getTopLevelConfig();
59
+ const owned = forConfig(config)[index];
60
+ if (owned.applyToEnvironment) {
61
+ const applied = await owned.applyToEnvironment(environment);
62
+ if (applied !== true) return applied;
63
+ }
64
+ const bound = Object.fromEntries(Object.entries(plugin).filter(([name]) => !topLevelHooks.has(name)));
65
+ for (const [name, hook] of Object.entries(bound)) {
66
+ const handler = typeof hook === "function" ? hook : hook && typeof hook === "object" && "handler" in hook ? hook.handler : void 0;
67
+ if (typeof handler !== "function") continue;
68
+ const invoke = function(...args) {
69
+ return invocationConfig.run(config, () => handler.apply(this, args));
70
+ };
71
+ bound[name] = typeof hook === "function" ? invoke : {
72
+ ...hook,
73
+ handler: invoke
74
+ };
75
+ }
76
+ return bound;
77
+ };
78
+ return plugin;
79
+ });
80
+ }
81
+ export { scopePlugins };
@@ -0,0 +1,3 @@
1
+ import fs from "fs";
2
+ declare function writeFile(filePath: string, data: string | NodeJS.ArrayBufferView, options?: fs.WriteFileOptions): void;
3
+ export { writeFile as default };
@@ -0,0 +1,9 @@
1
+ import fs from "fs";
2
+ import path from "path";
3
+ // src/utils/write-file.ts
4
+ function writeFile(filePath, data, options) {
5
+ const dirname = path.dirname(filePath);
6
+ if (!fs.existsSync(dirname)) fs.mkdirSync(dirname, { recursive: true });
7
+ fs.writeFileSync(filePath, data, options);
8
+ }
9
+ export { writeFile as default };
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "name": "@master/css-vite",
3
+ "type": "module",
4
+ "engines": {
5
+ "node": "^24"
6
+ },
7
+ "license": "MIT",
8
+ "description": "Vite plugin for Master CSS",
9
+ "author": "Aoyue Design LLC.",
10
+ "homepage": "https://css.master.co",
11
+ "bugs": {
12
+ "url": "https://github.com/master-co/css/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/master-co/css.git",
17
+ "directory": "packages/vite"
18
+ },
19
+ "keywords": [
20
+ "plugin",
21
+ "integration",
22
+ "vite",
23
+ "build tools",
24
+ "static rendering",
25
+ "static",
26
+ "runtime",
27
+ "css runtime",
28
+ "css",
29
+ "mastercss",
30
+ "vite-plugin"
31
+ ],
32
+ "sideEffects": false,
33
+ "types": "./dist/index.d.ts",
34
+ "exports": {
35
+ ".": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/index.js",
38
+ "default": "./dist/index.js"
39
+ }
40
+ },
41
+ "files": [
42
+ "dist"
43
+ ],
44
+ "publishConfig": {
45
+ "access": "public",
46
+ "provenance": true
47
+ },
48
+ "peerDependencies": {
49
+ "vite": ">=6"
50
+ },
51
+ "dependencies": {
52
+ "@master/css": "0.0.0-site.1793659883.g69c9aebcf628",
53
+ "@master/css-compiler": "0.0.0-site.1793659883.g69c9aebcf628",
54
+ "@master/css-tooling": "0.0.0-site.1793659883.g69c9aebcf628",
55
+ "@master/css-runtime": "0.0.0-site.1793659883.g69c9aebcf628",
56
+ "@master/css-server": "0.0.0-site.1793659883.g69c9aebcf628",
57
+ "magic-string": "^1.4.3",
58
+ "@master/css-schema": "0.0.0-site.1793659883.g69c9aebcf628"
59
+ },
60
+ "version": "0.0.0-site.1793659883.g69c9aebcf628",
61
+ "gitHead": "69c9aebcf628eb529001b9fa1b3536306f1b139e"
62
+ }