@plumeria/init 19.1.1

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/source.js ADDED
@@ -0,0 +1,413 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.readsMember = exports.callsFunction = exports.callsMethod = exports.importedFrom = exports.codeMask = exports.pluginsArrayOf = exports.configObjects = exports.directProperty = exports.moduleKindOf = exports.appendToConfigList = exports.wrapDefaultExport = exports.defaultExportOf = exports.appendInside = exports.appendToCall = exports.appendAtArray = exports.appendToArray = exports.addImport = exports.importsModule = exports.closerOf = void 0;
4
+ const PAIRS = { '(': ')', '[': ']', '{': '}' };
5
+ const endOfString = (source, start) => {
6
+ const quote = source[start];
7
+ for (let i = start + 1; i < source.length; i++) {
8
+ const char = source[i];
9
+ if (char === '\\') {
10
+ i++;
11
+ continue;
12
+ }
13
+ if (quote === '`' && char === '$' && source[i + 1] === '{') {
14
+ const closed = (0, exports.closerOf)(source, i + 1);
15
+ if (closed === -1)
16
+ return source.length - 1;
17
+ i = closed;
18
+ continue;
19
+ }
20
+ if (char === quote)
21
+ return i;
22
+ }
23
+ return source.length - 1;
24
+ };
25
+ const closerOf = (source, open) => {
26
+ const opener = source[open];
27
+ const closer = PAIRS[opener];
28
+ if (!closer)
29
+ return -1;
30
+ let depth = 0;
31
+ for (let i = open; i < source.length; i++) {
32
+ const char = source[i];
33
+ if (char === '/' && source[i + 1] === '/') {
34
+ const line = source.indexOf('\n', i);
35
+ if (line === -1)
36
+ return -1;
37
+ i = line;
38
+ continue;
39
+ }
40
+ if (char === '/' && source[i + 1] === '*') {
41
+ const end = source.indexOf('*/', i + 2);
42
+ if (end === -1)
43
+ return -1;
44
+ i = end + 1;
45
+ continue;
46
+ }
47
+ if (char === '"' || char === "'" || char === '`') {
48
+ i = endOfString(source, i);
49
+ continue;
50
+ }
51
+ if (char === opener)
52
+ depth++;
53
+ else if (char === closer) {
54
+ depth--;
55
+ if (depth === 0)
56
+ return i;
57
+ }
58
+ }
59
+ return -1;
60
+ };
61
+ exports.closerOf = closerOf;
62
+ const lineStartOf = (source, index) => source.lastIndexOf('\n', index) + 1;
63
+ const indentOf = (source, index) => {
64
+ const start = lineStartOf(source, index);
65
+ return /^[ \t]*/.exec(source.slice(start))[0];
66
+ };
67
+ const importsModule = (source, specifier) => new RegExp(`(from|require\\()\\s*['"]${specifier.replace(/[/@.]/g, '\\$&')}['"]`).test(source);
68
+ exports.importsModule = importsModule;
69
+ const addImport = (source, statement) => {
70
+ const pattern = /^[ \t]*(?:import\b[^\n]*|(?:const|let|var)\b[^\n]*require\([^\n]*)\n/gm;
71
+ let end = 0;
72
+ for (let match = pattern.exec(source); match; match = pattern.exec(source)) {
73
+ end = match.index + match[0].length;
74
+ }
75
+ if (end === 0)
76
+ return `${statement}\n${source}`;
77
+ return `${source.slice(0, end)}${statement}\n${source.slice(end)}`;
78
+ };
79
+ exports.addImport = addImport;
80
+ const appendToArray = (source, key, entry) => {
81
+ const pattern = new RegExp(`\\b${key}\\s*:\\s*\\[`);
82
+ const match = pattern.exec(source);
83
+ if (!match)
84
+ return undefined;
85
+ return (0, exports.appendAtArray)(source, match.index + match[0].length - 1, entry);
86
+ };
87
+ exports.appendToArray = appendToArray;
88
+ const appendAtArray = (source, open, entry) => {
89
+ if (source[open] !== '[')
90
+ return undefined;
91
+ const close = (0, exports.closerOf)(source, open);
92
+ if (close === -1)
93
+ return undefined;
94
+ const body = source.slice(open + 1, close);
95
+ if (body.trim() === '') {
96
+ return `${source.slice(0, open + 1)}${entry}${source.slice(close)}`;
97
+ }
98
+ if (!body.includes('\n')) {
99
+ const trimmed = body.replace(/,\s*$/, '');
100
+ return `${source.slice(0, open + 1)}${trimmed}, ${entry}${source.slice(close)}`;
101
+ }
102
+ const base = indentOf(source, open);
103
+ const inner = `${base} `;
104
+ const trimmed = body.replace(/,?\s*$/, '');
105
+ return `${source.slice(0, open + 1)}${trimmed},\n${inner}${entry},\n${base}${source.slice(close)}`;
106
+ };
107
+ exports.appendAtArray = appendAtArray;
108
+ const appendToCall = (source, callee, entries) => {
109
+ const pattern = new RegExp(`\\b${callee}\\s*\\(`);
110
+ const match = pattern.exec(source);
111
+ if (!match)
112
+ return undefined;
113
+ return (0, exports.appendInside)(source, match.index + match[0].length - 1, entries);
114
+ };
115
+ exports.appendToCall = appendToCall;
116
+ const appendInside = (source, open, entries) => {
117
+ const close = (0, exports.closerOf)(source, open);
118
+ if (close === -1)
119
+ return undefined;
120
+ const base = indentOf(source, open);
121
+ const inner = `${base} `;
122
+ const trimmed = source.slice(open + 1, close).replace(/,?\s*$/, '');
123
+ const head = trimmed === '' ? '' : `${trimmed},\n`;
124
+ const added = entries
125
+ .map((entry) => entry
126
+ .split('\n')
127
+ .map((line) => `${inner}${line}`)
128
+ .join('\n'))
129
+ .map((entry) => `${entry},`)
130
+ .join('\n');
131
+ return `${source.slice(0, open + 1)}${head}${added}\n${base}${source.slice(close)}`;
132
+ };
133
+ exports.appendInside = appendInside;
134
+ const defaultExportOf = (source) => {
135
+ const match = /^[ \t]*(export default|module\.exports\s*=)[ \t]*/m.exec(source);
136
+ if (!match)
137
+ return undefined;
138
+ const start = match.index + match[0].length;
139
+ let depth = 0;
140
+ let end = source.length;
141
+ for (let i = start; i < source.length; i++) {
142
+ const char = source[i];
143
+ if (char === '"' || char === "'" || char === '`') {
144
+ i = endOfString(source, i);
145
+ continue;
146
+ }
147
+ if (char === '(' || char === '[' || char === '{') {
148
+ depth++;
149
+ continue;
150
+ }
151
+ if (char === ')' || char === ']' || char === '}') {
152
+ depth--;
153
+ continue;
154
+ }
155
+ if (depth === 0 && (char === ';' || char === '\n')) {
156
+ end = i;
157
+ break;
158
+ }
159
+ }
160
+ return {
161
+ keyword: match[1],
162
+ start,
163
+ end,
164
+ expression: source.slice(start, end).trim(),
165
+ };
166
+ };
167
+ exports.defaultExportOf = defaultExportOf;
168
+ const wrapDefaultExport = (source, wrapper, extra = '') => {
169
+ const exported = (0, exports.defaultExportOf)(source);
170
+ if (!exported)
171
+ return undefined;
172
+ if (exported.expression.startsWith(`${wrapper}(`))
173
+ return source;
174
+ return `${source.slice(0, exported.start)}${wrapper}(${exported.expression}${extra})${source.slice(exported.end)}`;
175
+ };
176
+ exports.wrapDefaultExport = wrapDefaultExport;
177
+ const appendToConfigList = (source, entries) => {
178
+ const exported = (0, exports.defaultExportOf)(source);
179
+ if (!exported)
180
+ return undefined;
181
+ if (exported.expression.startsWith('[')) {
182
+ return (0, exports.appendInside)(source, source.indexOf('[', exported.start), entries);
183
+ }
184
+ const call = /^([A-Za-z_$][\w$]*)\s*\(/.exec(exported.expression);
185
+ if (!call)
186
+ return undefined;
187
+ return (0, exports.appendToCall)(source, call[1], entries);
188
+ };
189
+ exports.appendToConfigList = appendToConfigList;
190
+ const moduleKindOf = (file, source) => {
191
+ if (file.endsWith('.cjs'))
192
+ return 'cjs';
193
+ if (file.endsWith('.mjs') || file.endsWith('.ts') || file.endsWith('.mts'))
194
+ return 'esm';
195
+ if (/^[ \t]*(import\b|export\b)/m.test(source))
196
+ return 'esm';
197
+ if (/\brequire\s*\(|\bmodule\.exports\b/.test(source))
198
+ return 'cjs';
199
+ return 'esm';
200
+ };
201
+ exports.moduleKindOf = moduleKindOf;
202
+ const directProperty = (source, open, key) => {
203
+ if (source[open] !== '{')
204
+ return undefined;
205
+ const close = (0, exports.closerOf)(source, open);
206
+ if (close === -1)
207
+ return undefined;
208
+ const pattern = new RegExp(`^${key}\\s*:\\s*`);
209
+ for (let i = open + 1; i < close; i++) {
210
+ const char = source[i];
211
+ if (char === '/' && source[i + 1] === '/') {
212
+ const line = source.indexOf('\n', i);
213
+ if (line === -1)
214
+ return undefined;
215
+ i = line;
216
+ continue;
217
+ }
218
+ if (char === '/' && source[i + 1] === '*') {
219
+ const end = source.indexOf('*/', i + 2);
220
+ if (end === -1)
221
+ return undefined;
222
+ i = end + 1;
223
+ continue;
224
+ }
225
+ if (char === '"' || char === "'" || char === '`') {
226
+ i = endOfString(source, i);
227
+ continue;
228
+ }
229
+ if (char === '(' || char === '[' || char === '{') {
230
+ const inner = (0, exports.closerOf)(source, i);
231
+ if (inner === -1)
232
+ return undefined;
233
+ i = inner;
234
+ continue;
235
+ }
236
+ if (/[A-Za-z0-9_$]/.test(source[i - 1] ?? ''))
237
+ continue;
238
+ const match = pattern.exec(source.slice(i, close));
239
+ if (match)
240
+ return i + match[0].length;
241
+ }
242
+ return undefined;
243
+ };
244
+ exports.directProperty = directProperty;
245
+ const configObjects = (source) => {
246
+ const found = [];
247
+ const exported = (0, exports.defaultExportOf)(source);
248
+ if (exported && source[exported.start] === '{')
249
+ found.push(exported.start);
250
+ const pattern = /(?:\(|=>)\s*\(?\s*\{/g;
251
+ for (let match = pattern.exec(source); match; match = pattern.exec(source)) {
252
+ const at = match.index + match[0].length - 1;
253
+ if (!found.includes(at))
254
+ found.push(at);
255
+ }
256
+ return found;
257
+ };
258
+ exports.configObjects = configObjects;
259
+ const pluginsArrayOf = (source) => {
260
+ const objects = (0, exports.configObjects)(source);
261
+ for (const open of objects) {
262
+ const at = (0, exports.directProperty)(source, open, 'plugins');
263
+ if (at !== undefined && source[at] === '[')
264
+ return at;
265
+ }
266
+ for (const open of objects) {
267
+ const vite = (0, exports.directProperty)(source, open, 'vite');
268
+ if (vite === undefined || source[vite] !== '{')
269
+ continue;
270
+ const at = (0, exports.directProperty)(source, vite, 'plugins');
271
+ if (at !== undefined && source[at] === '[')
272
+ return at;
273
+ }
274
+ return undefined;
275
+ };
276
+ exports.pluginsArrayOf = pluginsArrayOf;
277
+ const REGEX_AFTER = new Set([
278
+ 'return',
279
+ 'typeof',
280
+ 'case',
281
+ 'in',
282
+ 'of',
283
+ 'new',
284
+ 'delete',
285
+ 'void',
286
+ 'do',
287
+ 'else',
288
+ 'yield',
289
+ 'await',
290
+ ]);
291
+ const codeMask = (source) => {
292
+ const masked = source.split('');
293
+ const blank = (start, end) => {
294
+ for (let i = start; i < end; i++) {
295
+ if (source[i] !== '\n' && source[i] !== '\r')
296
+ masked[i] = ' ';
297
+ }
298
+ };
299
+ const regexCanStartAfter = (index) => {
300
+ for (let i = index - 1; i >= 0; i--) {
301
+ if (/\s/.test(source[i]))
302
+ continue;
303
+ if (/[([{,:;=!?&|+\-*%^~<>]/.test(source[i]))
304
+ return true;
305
+ if (!/[A-Za-z0-9_$]/.test(source[i]))
306
+ return false;
307
+ const word = /[A-Za-z0-9_$]+$/.exec(source.slice(0, i + 1))?.[0] ?? '';
308
+ return REGEX_AFTER.has(word);
309
+ }
310
+ return true;
311
+ };
312
+ for (let i = 0; i < source.length; i++) {
313
+ const char = source[i];
314
+ if (char === '/' && source[i + 1] === '/') {
315
+ const end = source.indexOf('\n', i + 2);
316
+ const close = end === -1 ? source.length : end;
317
+ blank(i, close);
318
+ i = close - 1;
319
+ continue;
320
+ }
321
+ if (char === '/' && source[i + 1] === '*') {
322
+ const end = source.indexOf('*/', i + 2);
323
+ const close = end === -1 ? source.length : end + 2;
324
+ blank(i, close);
325
+ i = close - 1;
326
+ continue;
327
+ }
328
+ if (char === '"' || char === "'" || char === '`') {
329
+ const close = endOfString(source, i);
330
+ blank(i, close + 1);
331
+ i = close;
332
+ continue;
333
+ }
334
+ if (char === '/' && regexCanStartAfter(i)) {
335
+ let close = i + 1;
336
+ let inClass = false;
337
+ for (; close < source.length; close++) {
338
+ if (source[close] === '\\') {
339
+ close++;
340
+ continue;
341
+ }
342
+ if (source[close] === '[')
343
+ inClass = true;
344
+ else if (source[close] === ']')
345
+ inClass = false;
346
+ else if (source[close] === '/' && !inClass) {
347
+ close++;
348
+ while (/[A-Za-z]/.test(source[close] ?? ''))
349
+ close++;
350
+ break;
351
+ }
352
+ else if (source[close] === '\n' || source[close] === '\r') {
353
+ break;
354
+ }
355
+ }
356
+ blank(i, close);
357
+ i = close - 1;
358
+ }
359
+ }
360
+ return masked.join('');
361
+ };
362
+ exports.codeMask = codeMask;
363
+ const bindingNames = (binding) => {
364
+ const names = [];
365
+ const braced = /\{([^}]*)\}/.exec(binding);
366
+ for (const part of binding.replace(/\{[^}]*\}/g, ' ').split(',')) {
367
+ const name = /([A-Za-z_$][\w$]*)/.exec(part.replace(/^\s*\*\s*as\s+/, '').replace(/^\s*type\s+/, ''));
368
+ if (name)
369
+ names.push(name[1]);
370
+ }
371
+ if (braced) {
372
+ for (const part of braced[1].split(',')) {
373
+ const pieces = part.trim().split(/\s+as\s+/);
374
+ const name = /([A-Za-z_$][\w$]*)/.exec(pieces[pieces.length - 1] ?? '');
375
+ if (name)
376
+ names.push(name[1]);
377
+ }
378
+ }
379
+ return names;
380
+ };
381
+ const importedFrom = (source, specifier) => {
382
+ const escaped = specifier.replace(/[/@.]/g, '\\$&');
383
+ const quoted = `['"]${escaped}['"]`;
384
+ const patterns = [
385
+ new RegExp(`\\bimport\\s+([^;'"]*?)\\s+from\\s*${quoted}`, 'g'),
386
+ new RegExp(`\\b(?:const|let|var)\\s+([^;'"=]*?)\\s*=\\s*require\\(\\s*${quoted}`, 'g'),
387
+ new RegExp(`\\bimport\\s*()${quoted}`, 'g'),
388
+ ];
389
+ const names = [];
390
+ const cuts = [];
391
+ const code = (0, exports.codeMask)(source);
392
+ for (const pattern of patterns) {
393
+ for (let match = pattern.exec(source); match; match = pattern.exec(source)) {
394
+ const keyword = /\b(?:import|const|let|var|require)\b/.exec(match[0]);
395
+ if (!keyword || code[match.index + keyword.index] === ' ')
396
+ continue;
397
+ cuts.push([match.index, match.index + match[0].length]);
398
+ names.push(...bindingNames(match[1] ?? ''));
399
+ }
400
+ }
401
+ let rest = source;
402
+ for (const [start, end] of cuts.sort((a, b) => b[0] - a[0])) {
403
+ rest = `${rest.slice(0, start)}${rest.slice(end)}`;
404
+ }
405
+ return { names: [...new Set(names)], rest };
406
+ };
407
+ exports.importedFrom = importedFrom;
408
+ const callsMethod = (source, name) => new RegExp(`\\b${name}\\s*\\.\\s*[A-Za-z_$][\\w$]*\\s*\\(`).test((0, exports.codeMask)(source));
409
+ exports.callsMethod = callsMethod;
410
+ const callsFunction = (source, name) => new RegExp(`\\b${name}\\s*\\(`).test((0, exports.codeMask)(source));
411
+ exports.callsFunction = callsFunction;
412
+ const readsMember = (source, name, member) => new RegExp(`\\b${name}\\s*\\.\\s*${member}\\b`).test((0, exports.codeMask)(source));
413
+ exports.readsMember = readsMember;
@@ -0,0 +1,16 @@
1
+ import { styleText } from 'node:util';
2
+ type Format = Parameters<typeof styleText>[0];
3
+ export declare const paint: (stream: NodeJS.WritableStream, format: Format, text: string) => string;
4
+ export declare const style: {
5
+ ok: (text: string) => string;
6
+ install: (text: string) => string;
7
+ write: (text: string) => string;
8
+ patch: (text: string) => string;
9
+ manual: (text: string) => string;
10
+ skip: (text: string) => string;
11
+ strong: (text: string) => string;
12
+ faint: (text: string) => string;
13
+ choice: (text: string) => string;
14
+ failure: (text: string) => string;
15
+ };
16
+ export {};
package/dist/style.js ADDED
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.style = exports.paint = void 0;
4
+ const node_util_1 = require("node:util");
5
+ const paint = (stream, format, text) => (0, node_util_1.styleText)(format, text, { validateStream: true, stream });
6
+ exports.paint = paint;
7
+ const on = (stream) => (format) => (text) => (0, exports.paint)(stream, format, text);
8
+ const out = on(process.stdout);
9
+ const err = on(process.stderr);
10
+ exports.style = {
11
+ ok: out('green'),
12
+ install: out('cyan'),
13
+ write: out('green'),
14
+ patch: out('yellow'),
15
+ manual: out('red'),
16
+ skip: out('dim'),
17
+ strong: out('bold'),
18
+ faint: out('dim'),
19
+ choice: out(['bold', 'cyan']),
20
+ failure: err('red'),
21
+ };
package/package.json ADDED
@@ -0,0 +1,41 @@
1
+ {
2
+ "name": "@plumeria/init",
3
+ "version": "19.1.1",
4
+ "description": "One command that sets up Plumeria: detects the bundler, installs the packages, writes the configs",
5
+ "author": "Refirst 11",
6
+ "license": "MIT",
7
+ "funding": "https://github.com/sponsors/refirst11",
8
+ "homepage": "https://plumeria.dev",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "git+https://github.com/zss-in-js/plumeria.git",
12
+ "directory": "packages/init"
13
+ },
14
+ "bugs": {
15
+ "url": "https://github.com/zss-in-js/plumeria/issues"
16
+ },
17
+ "keywords": [
18
+ "plumeria",
19
+ "init",
20
+ "setup",
21
+ "cli",
22
+ "css-in-js"
23
+ ],
24
+ "sideEffects": false,
25
+ "main": "dist/index.js",
26
+ "types": "dist/index.d.ts",
27
+ "bin": {
28
+ "plumeria-init": "bin/init.js"
29
+ },
30
+ "files": [
31
+ "dist/",
32
+ "bin/"
33
+ ],
34
+ "scripts": {
35
+ "build": "rimraf dist && pnpm cjs",
36
+ "cjs": "tsc --project tsconfig.cjs.json"
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ }
41
+ }