@plumeria/unplugin 19.2.12 → 19.2.14

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/core.js CHANGED
@@ -42,6 +42,7 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
42
42
  const filter = (0, pluginutils_1.createFilter)(options.include, options.exclude);
43
43
  const propertyPolicy = (0, utils_1.resolvePropertyPolicy)(options);
44
44
  const styleProp = options.styleProp ?? utils_1.DEFAULT_STYLE_PROP;
45
+ let classProp;
45
46
  const cssLookup = new Map();
46
47
  const cssFileLookup = new Map();
47
48
  const targets = [];
@@ -67,6 +68,9 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
67
68
  setCssImport(formatter) {
68
69
  cssImport = formatter;
69
70
  },
71
+ setClassProp(value) {
72
+ classProp = value;
73
+ },
70
74
  },
71
75
  resolveId(id, importer) {
72
76
  const [pathId, query] = id.split('?');
@@ -94,82 +98,86 @@ const unpluginFactory = (options = {}, unpluginMeta) => {
94
98
  transformInclude(id) {
95
99
  return filter(id);
96
100
  },
97
- async transform(source, id) {
98
- if (id.includes('node_modules'))
99
- return null;
100
- if (!source.includes('@plumeria/core'))
101
- return null;
102
- const [baseId] = id.split('?');
103
- if (!filter(baseId))
104
- return null;
105
- const dependencies = [];
106
- const addDependency = (depPath) => {
107
- dependencies.push(depPath);
108
- if (this.addWatchFile) {
109
- this.addWatchFile(depPath);
110
- }
111
- };
112
- const { code: transformedSource, sheets: extractedSheets } = await (0, utils_1.transformSource)({
113
- source,
114
- moduleId: id,
115
- filePath: baseId,
116
- root: viteRoot,
117
- styleProp,
118
- propertyPolicy,
119
- isDev,
120
- collectOndemandSheets: true,
121
- addDependency,
122
- });
123
- const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
124
- const cssFilename = `${baseId.replace(exports.EXTENSION_PATTERN, '')}.zero.css`;
125
- const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
126
- if (isDev) {
127
- if (!devCssSheets.has(cssFilename)) {
128
- devCssSheets.set(cssFilename, new Set());
129
- }
130
- const acc = devCssSheets.get(cssFilename);
131
- extractedSheets.forEach((sheet) => {
132
- acc.delete(sheet);
133
- acc.add(sheet);
101
+ transform: {
102
+ order: 'pre',
103
+ async handler(source, id) {
104
+ if (id.includes('node_modules'))
105
+ return null;
106
+ if (!source.includes('@plumeria/core'))
107
+ return null;
108
+ const [baseId] = id.split('?');
109
+ if (!filter(baseId))
110
+ return null;
111
+ const dependencies = [];
112
+ const addDependency = (depPath) => {
113
+ dependencies.push(depPath);
114
+ if (this.addWatchFile) {
115
+ this.addWatchFile(depPath);
116
+ }
117
+ };
118
+ const { code: transformedSource, sheets: extractedSheets } = await (0, utils_1.transformSource)({
119
+ source,
120
+ moduleId: id,
121
+ filePath: baseId,
122
+ root: viteRoot,
123
+ styleProp,
124
+ classProp,
125
+ propertyPolicy,
126
+ isDev,
127
+ collectOndemandSheets: true,
128
+ addDependency,
134
129
  });
135
- const accCSS = await (0, utils_1.optimizer)(Array.from(acc).join(''));
136
- cssLookup.set(cssFilename, accCSS);
137
- }
138
- else {
139
- cssLookup.set(cssFilename, optInCSS);
140
- }
141
- cssFileLookup.set(cssId, cssFilename);
142
- if (extractedSheets.length > 0) {
143
- const targetIndex = targets.findIndex((t) => t.id === id);
144
- if (targetIndex !== -1) {
145
- targets[targetIndex].dependencies = dependencies;
130
+ const optInCSS = await (0, utils_1.optimizer)(extractedSheets.join(''));
131
+ const cssFilename = `${baseId.replace(exports.EXTENSION_PATTERN, '')}.zero.css`;
132
+ const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
133
+ if (isDev) {
134
+ if (!devCssSheets.has(cssFilename)) {
135
+ devCssSheets.set(cssFilename, new Set());
136
+ }
137
+ const acc = devCssSheets.get(cssFilename);
138
+ extractedSheets.forEach((sheet) => {
139
+ acc.delete(sheet);
140
+ acc.add(sheet);
141
+ });
142
+ const accCSS = await (0, utils_1.optimizer)(Array.from(acc).join(''));
143
+ cssLookup.set(cssFilename, accCSS);
146
144
  }
147
145
  else {
148
- targets.push({ id, dependencies });
146
+ cssLookup.set(cssFilename, optInCSS);
149
147
  }
150
- const statement = cssImport
151
- ? cssImport({
152
- id,
153
- cssId,
154
- cssFilename,
155
- css: cssLookup.get(cssFilename) ?? '',
156
- })
157
- : `\nimport ${JSON.stringify(cssId)};`;
158
- return {
159
- code: statement ? transformedSource + statement : transformedSource,
160
- map: null,
161
- };
162
- }
163
- else {
164
- const targetIndex = targets.findIndex((t) => t.id === id);
165
- if (targetIndex !== -1) {
166
- targets.splice(targetIndex, 1);
148
+ cssFileLookup.set(cssId, cssFilename);
149
+ if (extractedSheets.length > 0) {
150
+ const targetIndex = targets.findIndex((t) => t.id === id);
151
+ if (targetIndex !== -1) {
152
+ targets[targetIndex].dependencies = dependencies;
153
+ }
154
+ else {
155
+ targets.push({ id, dependencies });
156
+ }
157
+ const statement = cssImport
158
+ ? cssImport({
159
+ id,
160
+ cssId,
161
+ cssFilename,
162
+ css: cssLookup.get(cssFilename) ?? '',
163
+ })
164
+ : `\nimport ${JSON.stringify(cssId)};`;
165
+ return {
166
+ code: statement ? transformedSource + statement : transformedSource,
167
+ map: null,
168
+ };
167
169
  }
168
- return {
169
- code: transformedSource,
170
- map: null,
171
- };
172
- }
170
+ else {
171
+ const targetIndex = targets.findIndex((t) => t.id === id);
172
+ if (targetIndex !== -1) {
173
+ targets.splice(targetIndex, 1);
174
+ }
175
+ return {
176
+ code: transformedSource,
177
+ map: null,
178
+ };
179
+ }
180
+ },
173
181
  },
174
182
  };
175
183
  };
package/dist/core.mjs CHANGED
@@ -6,6 +6,7 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
6
6
  const filter = createFilter(options.include, options.exclude);
7
7
  const propertyPolicy = resolvePropertyPolicy(options);
8
8
  const styleProp = options.styleProp ?? DEFAULT_STYLE_PROP;
9
+ let classProp;
9
10
  const cssLookup = new Map();
10
11
  const cssFileLookup = new Map();
11
12
  const targets = [];
@@ -31,6 +32,9 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
31
32
  setCssImport(formatter) {
32
33
  cssImport = formatter;
33
34
  },
35
+ setClassProp(value) {
36
+ classProp = value;
37
+ },
34
38
  },
35
39
  resolveId(id, importer) {
36
40
  const [pathId, query] = id.split('?');
@@ -58,82 +62,86 @@ export const unpluginFactory = (options = {}, unpluginMeta) => {
58
62
  transformInclude(id) {
59
63
  return filter(id);
60
64
  },
61
- async transform(source, id) {
62
- if (id.includes('node_modules'))
63
- return null;
64
- if (!source.includes('@plumeria/core'))
65
- return null;
66
- const [baseId] = id.split('?');
67
- if (!filter(baseId))
68
- return null;
69
- const dependencies = [];
70
- const addDependency = (depPath) => {
71
- dependencies.push(depPath);
72
- if (this.addWatchFile) {
73
- this.addWatchFile(depPath);
74
- }
75
- };
76
- const { code: transformedSource, sheets: extractedSheets } = await transformSource({
77
- source,
78
- moduleId: id,
79
- filePath: baseId,
80
- root: viteRoot,
81
- styleProp,
82
- propertyPolicy,
83
- isDev,
84
- collectOndemandSheets: true,
85
- addDependency,
86
- });
87
- const optInCSS = await optimizer(extractedSheets.join(''));
88
- const cssFilename = `${baseId.replace(EXTENSION_PATTERN, '')}.zero.css`;
89
- const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
90
- if (isDev) {
91
- if (!devCssSheets.has(cssFilename)) {
92
- devCssSheets.set(cssFilename, new Set());
93
- }
94
- const acc = devCssSheets.get(cssFilename);
95
- extractedSheets.forEach((sheet) => {
96
- acc.delete(sheet);
97
- acc.add(sheet);
65
+ transform: {
66
+ order: 'pre',
67
+ async handler(source, id) {
68
+ if (id.includes('node_modules'))
69
+ return null;
70
+ if (!source.includes('@plumeria/core'))
71
+ return null;
72
+ const [baseId] = id.split('?');
73
+ if (!filter(baseId))
74
+ return null;
75
+ const dependencies = [];
76
+ const addDependency = (depPath) => {
77
+ dependencies.push(depPath);
78
+ if (this.addWatchFile) {
79
+ this.addWatchFile(depPath);
80
+ }
81
+ };
82
+ const { code: transformedSource, sheets: extractedSheets } = await transformSource({
83
+ source,
84
+ moduleId: id,
85
+ filePath: baseId,
86
+ root: viteRoot,
87
+ styleProp,
88
+ classProp,
89
+ propertyPolicy,
90
+ isDev,
91
+ collectOndemandSheets: true,
92
+ addDependency,
98
93
  });
99
- const accCSS = await optimizer(Array.from(acc).join(''));
100
- cssLookup.set(cssFilename, accCSS);
101
- }
102
- else {
103
- cssLookup.set(cssFilename, optInCSS);
104
- }
105
- cssFileLookup.set(cssId, cssFilename);
106
- if (extractedSheets.length > 0) {
107
- const targetIndex = targets.findIndex((t) => t.id === id);
108
- if (targetIndex !== -1) {
109
- targets[targetIndex].dependencies = dependencies;
94
+ const optInCSS = await optimizer(extractedSheets.join(''));
95
+ const cssFilename = `${baseId.replace(EXTENSION_PATTERN, '')}.zero.css`;
96
+ const cssId = `/${path.relative(viteRoot, cssFilename).replace(/\\/g, '/')}`;
97
+ if (isDev) {
98
+ if (!devCssSheets.has(cssFilename)) {
99
+ devCssSheets.set(cssFilename, new Set());
100
+ }
101
+ const acc = devCssSheets.get(cssFilename);
102
+ extractedSheets.forEach((sheet) => {
103
+ acc.delete(sheet);
104
+ acc.add(sheet);
105
+ });
106
+ const accCSS = await optimizer(Array.from(acc).join(''));
107
+ cssLookup.set(cssFilename, accCSS);
110
108
  }
111
109
  else {
112
- targets.push({ id, dependencies });
110
+ cssLookup.set(cssFilename, optInCSS);
113
111
  }
114
- const statement = cssImport
115
- ? cssImport({
116
- id,
117
- cssId,
118
- cssFilename,
119
- css: cssLookup.get(cssFilename) ?? '',
120
- })
121
- : `\nimport ${JSON.stringify(cssId)};`;
122
- return {
123
- code: statement ? transformedSource + statement : transformedSource,
124
- map: null,
125
- };
126
- }
127
- else {
128
- const targetIndex = targets.findIndex((t) => t.id === id);
129
- if (targetIndex !== -1) {
130
- targets.splice(targetIndex, 1);
112
+ cssFileLookup.set(cssId, cssFilename);
113
+ if (extractedSheets.length > 0) {
114
+ const targetIndex = targets.findIndex((t) => t.id === id);
115
+ if (targetIndex !== -1) {
116
+ targets[targetIndex].dependencies = dependencies;
117
+ }
118
+ else {
119
+ targets.push({ id, dependencies });
120
+ }
121
+ const statement = cssImport
122
+ ? cssImport({
123
+ id,
124
+ cssId,
125
+ cssFilename,
126
+ css: cssLookup.get(cssFilename) ?? '',
127
+ })
128
+ : `\nimport ${JSON.stringify(cssId)};`;
129
+ return {
130
+ code: statement ? transformedSource + statement : transformedSource,
131
+ map: null,
132
+ };
131
133
  }
132
- return {
133
- code: transformedSource,
134
- map: null,
135
- };
136
- }
134
+ else {
135
+ const targetIndex = targets.findIndex((t) => t.id === id);
136
+ if (targetIndex !== -1) {
137
+ targets.splice(targetIndex, 1);
138
+ }
139
+ return {
140
+ code: transformedSource,
141
+ map: null,
142
+ };
143
+ }
144
+ },
137
145
  },
138
146
  };
139
147
  };
package/dist/vite.js CHANGED
@@ -48,7 +48,7 @@ function isRscConfig(userConfig) {
48
48
  }
49
49
  function attachViteHooks(plugin, options) {
50
50
  let devServer;
51
- const { cssLookup, cssFileLookup, targets, setDev, setRoot, setCssImport } = plugin.__plumeriaInternal;
51
+ const { cssLookup, cssFileLookup, targets, setDev, setRoot, setCssImport, setClassProp, } = plugin.__plumeriaInternal;
52
52
  const useDiskEmit = options?.devEmitToDisk ?? false;
53
53
  let isDev = false;
54
54
  let viteRoot = process.cwd();
@@ -119,38 +119,41 @@ function attachViteHooks(plugin, options) {
119
119
  return false;
120
120
  };
121
121
  const baseTransform = plugin.transform;
122
- plugin.transform = async function (code, id) {
123
- const result = await baseTransform.call(this, code, id);
124
- if (!useDiskEmit &&
125
- devServer &&
126
- result &&
127
- typeof result === 'object' &&
128
- result.code.includes('.zero.css')) {
129
- const baseId = id.replace(core_1.EXTENSION_PATTERN, '');
130
- const cssFilename = `${baseId}.zero.css`;
131
- const cssContent = cssLookup.get(cssFilename) ?? '';
132
- const envName = this.environment?.name;
133
- const seenKey = `${envName ?? ''}:${cssFilename}`;
134
- if (envName && envName !== 'client') {
135
- if (lastServedCss.get(seenKey) !== cssContent) {
136
- lastServedCss.set(seenKey, cssContent);
137
- invalidateClientCss(cssFilename);
138
- }
139
- }
140
- else if (lastServedCss.get(seenKey) !== cssContent) {
141
- if (reloadClientCss(cssFilename)) {
142
- lastServedCss.set(seenKey, cssContent);
122
+ plugin.transform = {
123
+ order: 'pre',
124
+ async handler(code, id) {
125
+ const result = await baseTransform.handler.call(this, code, id);
126
+ if (!useDiskEmit &&
127
+ devServer &&
128
+ result &&
129
+ typeof result === 'object' &&
130
+ result.code.includes('.zero.css')) {
131
+ const baseId = id.replace(core_1.EXTENSION_PATTERN, '');
132
+ const cssFilename = `${baseId}.zero.css`;
133
+ const cssContent = cssLookup.get(cssFilename) ?? '';
134
+ const envName = this.environment?.name;
135
+ const seenKey = `${envName ?? ''}:${cssFilename}`;
136
+ if (envName && envName !== 'client') {
137
+ if (lastServedCss.get(seenKey) !== cssContent) {
138
+ lastServedCss.set(seenKey, cssContent);
139
+ invalidateClientCss(cssFilename);
140
+ }
143
141
  }
144
- else {
145
- const mod = devServer.moduleGraph.getModuleById(cssFilename);
146
- if (mod) {
142
+ else if (lastServedCss.get(seenKey) !== cssContent) {
143
+ if (reloadClientCss(cssFilename)) {
147
144
  lastServedCss.set(seenKey, cssContent);
148
- devServer.reloadModule(mod);
145
+ }
146
+ else {
147
+ const mod = devServer.moduleGraph.getModuleById(cssFilename);
148
+ if (mod) {
149
+ lastServedCss.set(seenKey, cssContent);
150
+ devServer.reloadModule(mod);
151
+ }
149
152
  }
150
153
  }
151
154
  }
152
- }
153
- return result;
155
+ return result;
156
+ },
154
157
  };
155
158
  const vitePlugin = {
156
159
  ...plugin,
@@ -210,6 +213,9 @@ function attachViteHooks(plugin, options) {
210
213
  configResolved(config) {
211
214
  viteRoot = config.root;
212
215
  setRoot(config.root);
216
+ if (config.plugins?.some((entry) => entry?.name === 'solid')) {
217
+ setClassProp('class');
218
+ }
213
219
  if (config.command === 'serve') {
214
220
  isDev = true;
215
221
  setDev(true);
package/dist/vite.mjs CHANGED
@@ -13,7 +13,7 @@ function isRscConfig(userConfig) {
13
13
  }
14
14
  function attachViteHooks(plugin, options) {
15
15
  let devServer;
16
- const { cssLookup, cssFileLookup, targets, setDev, setRoot, setCssImport } = plugin.__plumeriaInternal;
16
+ const { cssLookup, cssFileLookup, targets, setDev, setRoot, setCssImport, setClassProp, } = plugin.__plumeriaInternal;
17
17
  const useDiskEmit = options?.devEmitToDisk ?? false;
18
18
  let isDev = false;
19
19
  let viteRoot = process.cwd();
@@ -84,38 +84,41 @@ function attachViteHooks(plugin, options) {
84
84
  return false;
85
85
  };
86
86
  const baseTransform = plugin.transform;
87
- plugin.transform = async function (code, id) {
88
- const result = await baseTransform.call(this, code, id);
89
- if (!useDiskEmit &&
90
- devServer &&
91
- result &&
92
- typeof result === 'object' &&
93
- result.code.includes('.zero.css')) {
94
- const baseId = id.replace(EXTENSION_PATTERN, '');
95
- const cssFilename = `${baseId}.zero.css`;
96
- const cssContent = cssLookup.get(cssFilename) ?? '';
97
- const envName = this.environment?.name;
98
- const seenKey = `${envName ?? ''}:${cssFilename}`;
99
- if (envName && envName !== 'client') {
100
- if (lastServedCss.get(seenKey) !== cssContent) {
101
- lastServedCss.set(seenKey, cssContent);
102
- invalidateClientCss(cssFilename);
103
- }
104
- }
105
- else if (lastServedCss.get(seenKey) !== cssContent) {
106
- if (reloadClientCss(cssFilename)) {
107
- lastServedCss.set(seenKey, cssContent);
87
+ plugin.transform = {
88
+ order: 'pre',
89
+ async handler(code, id) {
90
+ const result = await baseTransform.handler.call(this, code, id);
91
+ if (!useDiskEmit &&
92
+ devServer &&
93
+ result &&
94
+ typeof result === 'object' &&
95
+ result.code.includes('.zero.css')) {
96
+ const baseId = id.replace(EXTENSION_PATTERN, '');
97
+ const cssFilename = `${baseId}.zero.css`;
98
+ const cssContent = cssLookup.get(cssFilename) ?? '';
99
+ const envName = this.environment?.name;
100
+ const seenKey = `${envName ?? ''}:${cssFilename}`;
101
+ if (envName && envName !== 'client') {
102
+ if (lastServedCss.get(seenKey) !== cssContent) {
103
+ lastServedCss.set(seenKey, cssContent);
104
+ invalidateClientCss(cssFilename);
105
+ }
108
106
  }
109
- else {
110
- const mod = devServer.moduleGraph.getModuleById(cssFilename);
111
- if (mod) {
107
+ else if (lastServedCss.get(seenKey) !== cssContent) {
108
+ if (reloadClientCss(cssFilename)) {
112
109
  lastServedCss.set(seenKey, cssContent);
113
- devServer.reloadModule(mod);
110
+ }
111
+ else {
112
+ const mod = devServer.moduleGraph.getModuleById(cssFilename);
113
+ if (mod) {
114
+ lastServedCss.set(seenKey, cssContent);
115
+ devServer.reloadModule(mod);
116
+ }
114
117
  }
115
118
  }
116
119
  }
117
- }
118
- return result;
120
+ return result;
121
+ },
119
122
  };
120
123
  const vitePlugin = {
121
124
  ...plugin,
@@ -175,6 +178,9 @@ function attachViteHooks(plugin, options) {
175
178
  configResolved(config) {
176
179
  viteRoot = config.root;
177
180
  setRoot(config.root);
181
+ if (config.plugins?.some((entry) => entry?.name === 'solid')) {
182
+ setClassProp('class');
183
+ }
178
184
  if (config.command === 'serve') {
179
185
  isDev = true;
180
186
  setDev(true);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/unplugin",
3
- "version": "19.2.12",
3
+ "version": "19.2.14",
4
4
  "description": "Universal Plumeria plugin for various build tools",
5
5
  "author": "Refirst 11",
6
6
  "license": "MIT",
@@ -94,7 +94,7 @@
94
94
  "dependencies": {
95
95
  "@rollup/pluginutils": "^5.4.0",
96
96
  "unplugin": "^3.0.0",
97
- "@plumeria/utils": "19.2.12"
97
+ "@plumeria/utils": "19.2.14"
98
98
  },
99
99
  "devDependencies": {
100
100
  "vite": "^8.0.13"