@plumeria/webpack-plugin 0.22.1 → 0.22.2

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/create.js CHANGED
@@ -88,12 +88,6 @@ function compileToSingleCSS(object) {
88
88
  return [...baseSheets, ...querySheets].join('\n');
89
89
  }
90
90
  function createCSS(object) {
91
- const result = {};
92
- Object.entries(object).forEach(([key, styleObj]) => {
93
- Object.defineProperty(result, key, {
94
- get: () => Object.freeze(styleObj),
95
- });
96
- });
97
91
  const compiledCSS = compileToSingleCSS(object);
98
92
  return compiledCSS;
99
93
  }
@@ -241,7 +241,6 @@ function resolveKeyframesTableMemberExpression(node, keyframesHashTable) {
241
241
  return keyframesHashTable[node.object.name];
242
242
  }
243
243
  }
244
- return undefined;
245
244
  }
246
245
  function resolveViewTransitionTableMemberExpression(node, viewTransitionHashTable) {
247
246
  if (t.isIdentifier(node)) {
@@ -252,27 +251,20 @@ function resolveViewTransitionTableMemberExpression(node, viewTransitionHashTabl
252
251
  return viewTransitionHashTable[node.object.name];
253
252
  }
254
253
  }
255
- return undefined;
256
254
  }
257
255
  function resolveConstTableMemberExpression(node, constTable) {
258
256
  if (t.isIdentifier(node.object) && t.isIdentifier(node.property)) {
259
257
  const varName = node.object.name;
260
258
  const key = node.property.name;
261
259
  const tableValue = constTable[varName];
262
- if (typeof tableValue === 'string') {
263
- return tableValue;
264
- }
265
260
  if (tableValue && typeof tableValue === 'object' && key in tableValue) {
266
261
  return tableValue[key];
267
262
  }
268
263
  }
269
264
  return undefined;
270
265
  }
271
- function resolveTokensTableMemberExpressionByNode(node, tokensTable, asObject = false) {
266
+ function resolveTokensTableMemberExpressionByNode(node, tokensTable) {
272
267
  if (t.isIdentifier(node)) {
273
- if (asObject && typeof tokensTable[node.name] === 'object') {
274
- return { ...tokensTable[node.name] };
275
- }
276
268
  const cssVarName = (0, zss_engine_1.camelToKebabCase)(node.name);
277
269
  return `var(--${cssVarName})`;
278
270
  }
@@ -288,20 +280,18 @@ function resolveTokensTableMemberExpressionByNode(node, tokensTable, asObject =
288
280
  if (key &&
289
281
  tokensTable[varName] &&
290
282
  tokensTable[varName][key] !== undefined) {
291
- if (asObject) {
292
- return { [key]: tokensTable[varName][key] };
293
- }
294
283
  const cssVarName = (0, zss_engine_1.camelToKebabCase)(key);
295
284
  return `var(--${cssVarName})`;
296
285
  }
297
286
  }
298
287
  return undefined;
299
288
  }
300
- function scanForDefineConsts() {
301
- const constTableLocal = {};
289
+ function scanForKeyframes() {
290
+ const keyframesHashTableLocal = {};
291
+ const keyframesObjectTableLocal = {};
302
292
  const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
303
293
  for (const filePath of files) {
304
- if (!isCSSDefineFile(filePath, 'defineConsts'))
294
+ if (!isCSSDefineFile(filePath, 'keyframes'))
305
295
  continue;
306
296
  this.addDependency(filePath);
307
297
  const source = fs_1.default.readFileSync(filePath, 'utf8');
@@ -311,9 +301,7 @@ function scanForDefineConsts() {
311
301
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
312
302
  ],
313
303
  });
314
- if (!ast)
315
- continue;
316
- for (const node of ast.program.body) {
304
+ for (const node of ast?.program.body) {
317
305
  let declarations = [];
318
306
  if (t.isVariableDeclaration(node)) {
319
307
  declarations = node.declarations;
@@ -329,23 +317,28 @@ function scanForDefineConsts() {
329
317
  t.isCallExpression(decl.init) &&
330
318
  t.isMemberExpression(decl.init.callee) &&
331
319
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
332
- t.isIdentifier(decl.init.callee.property, { name: 'defineConsts' }) &&
320
+ t.isIdentifier(decl.init.callee.property, { name: 'keyframes' }) &&
333
321
  t.isObjectExpression(decl.init.arguments[0])) {
334
322
  const varName = decl.id.name;
335
- const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, viewTransitionHashTable, tokensTable);
336
- constTableLocal[varName] = obj;
323
+ const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, viewTransitionHashTable, tokensTable);
324
+ const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
325
+ keyframesHashTableLocal[varName] = hash;
326
+ keyframesObjectTableLocal[hash] = obj;
337
327
  }
338
328
  }
339
329
  }
340
330
  }
341
- return constTableLocal;
331
+ return {
332
+ keyframesHashTableLocal,
333
+ keyframesObjectTableLocal,
334
+ };
342
335
  }
343
- function scanForKeyframes() {
344
- const keyframesHashTableLocal = {};
345
- const keyframesObjectTableLocal = {};
336
+ function scanForViewTransition() {
337
+ const viewTransitionHashTableLocal = {};
338
+ const viewTransitionObjectTableLocal = {};
346
339
  const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
347
340
  for (const filePath of files) {
348
- if (!isCSSDefineFile(filePath, 'keyframes'))
341
+ if (!isCSSDefineFile(filePath, 'viewTransition'))
349
342
  continue;
350
343
  this.addDependency(filePath);
351
344
  const source = fs_1.default.readFileSync(filePath, 'utf8');
@@ -355,9 +348,7 @@ function scanForKeyframes() {
355
348
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
356
349
  ],
357
350
  });
358
- if (!ast)
359
- continue;
360
- for (const node of ast.program.body) {
351
+ for (const node of ast?.program.body) {
361
352
  let declarations = [];
362
353
  if (t.isVariableDeclaration(node)) {
363
354
  declarations = node.declarations;
@@ -373,28 +364,29 @@ function scanForKeyframes() {
373
364
  t.isCallExpression(decl.init) &&
374
365
  t.isMemberExpression(decl.init.callee) &&
375
366
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
376
- t.isIdentifier(decl.init.callee.property, { name: 'keyframes' }) &&
367
+ t.isIdentifier(decl.init.callee.property, {
368
+ name: 'viewTransition',
369
+ }) &&
377
370
  t.isObjectExpression(decl.init.arguments[0])) {
378
371
  const varName = decl.id.name;
379
- const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTableLocal, viewTransitionHashTable, tokensTable);
372
+ const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTableLocal, tokensTable);
380
373
  const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
381
- keyframesHashTableLocal[varName] = hash;
382
- keyframesObjectTableLocal[hash] = obj;
374
+ viewTransitionHashTableLocal[varName] = hash;
375
+ viewTransitionObjectTableLocal[hash] = obj;
383
376
  }
384
377
  }
385
378
  }
386
379
  }
387
380
  return {
388
- keyframesHashTableLocal,
389
- keyframesObjectTableLocal,
381
+ viewTransitionHashTableLocal,
382
+ viewTransitionObjectTableLocal,
390
383
  };
391
384
  }
392
- function scanForDefineTokens() {
393
- const tokensTableLocal = {};
394
- const defineTokensObjectTableLocal = {};
385
+ function scanForDefineConsts() {
386
+ const constTableLocal = {};
395
387
  const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
396
388
  for (const filePath of files) {
397
- if (!isCSSDefineFile(filePath, 'defineTokens'))
389
+ if (!isCSSDefineFile(filePath, 'defineConsts'))
398
390
  continue;
399
391
  this.addDependency(filePath);
400
392
  const source = fs_1.default.readFileSync(filePath, 'utf8');
@@ -404,9 +396,7 @@ function scanForDefineTokens() {
404
396
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
405
397
  ],
406
398
  });
407
- if (!ast)
408
- continue;
409
- for (const node of ast.program.body) {
399
+ for (const node of ast?.program.body) {
410
400
  let declarations = [];
411
401
  if (t.isVariableDeclaration(node)) {
412
402
  declarations = node.declarations;
@@ -422,24 +412,23 @@ function scanForDefineTokens() {
422
412
  t.isCallExpression(decl.init) &&
423
413
  t.isMemberExpression(decl.init.callee) &&
424
414
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
425
- t.isIdentifier(decl.init.callee.property, { name: 'defineTokens' }) &&
415
+ t.isIdentifier(decl.init.callee.property, { name: 'defineConsts' }) &&
426
416
  t.isObjectExpression(decl.init.arguments[0])) {
427
417
  const varName = decl.id.name;
428
- const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTable, tokensTableLocal);
429
- tokensTableLocal[varName] = obj;
430
- defineTokensObjectTableLocal[varName] = obj;
418
+ const obj = objectExpressionToObject(decl.init.arguments[0], constTableLocal, keyframesHashTable, viewTransitionHashTable, tokensTable);
419
+ constTableLocal[varName] = obj;
431
420
  }
432
421
  }
433
422
  }
434
423
  }
435
- return { tokensTableLocal, defineTokensObjectTableLocal };
424
+ return constTableLocal;
436
425
  }
437
- function scanForViewTransition() {
438
- const viewTransitionHashTableLocal = {};
439
- const viewTransitionObjectTableLocal = {};
426
+ function scanForDefineTokens() {
427
+ const tokensTableLocal = {};
428
+ const defineTokensObjectTableLocal = {};
440
429
  const files = (0, glob_1.globSync)(PATTERN_PATH, GLOB_OPTIONS);
441
430
  for (const filePath of files) {
442
- if (!isCSSDefineFile(filePath, 'viewTransition'))
431
+ if (!isCSSDefineFile(filePath, 'defineTokens'))
443
432
  continue;
444
433
  this.addDependency(filePath);
445
434
  const source = fs_1.default.readFileSync(filePath, 'utf8');
@@ -449,9 +438,7 @@ function scanForViewTransition() {
449
438
  ['@babel/preset-typescript', { isTSX: true, allExtensions: true }],
450
439
  ],
451
440
  });
452
- if (!ast)
453
- continue;
454
- for (const node of ast.program.body) {
441
+ for (const node of ast?.program.body) {
455
442
  let declarations = [];
456
443
  if (t.isVariableDeclaration(node)) {
457
444
  declarations = node.declarations;
@@ -467,23 +454,17 @@ function scanForViewTransition() {
467
454
  t.isCallExpression(decl.init) &&
468
455
  t.isMemberExpression(decl.init.callee) &&
469
456
  t.isIdentifier(decl.init.callee.object, { name: 'css' }) &&
470
- t.isIdentifier(decl.init.callee.property, {
471
- name: 'viewTransition',
472
- }) &&
457
+ t.isIdentifier(decl.init.callee.property, { name: 'defineTokens' }) &&
473
458
  t.isObjectExpression(decl.init.arguments[0])) {
474
459
  const varName = decl.id.name;
475
- const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTableLocal, tokensTable);
476
- const hash = (0, zss_engine_1.genBase36Hash)(obj, 1, 8);
477
- viewTransitionHashTableLocal[varName] = hash;
478
- viewTransitionObjectTableLocal[hash] = obj;
460
+ const obj = objectExpressionToObject(decl.init.arguments[0], constTable, keyframesHashTable, viewTransitionHashTable, tokensTableLocal);
461
+ tokensTableLocal[varName] = obj;
462
+ defineTokensObjectTableLocal[varName] = obj;
479
463
  }
480
464
  }
481
465
  }
482
466
  }
483
- return {
484
- viewTransitionHashTableLocal,
485
- viewTransitionObjectTableLocal,
486
- };
467
+ return { tokensTableLocal, defineTokensObjectTableLocal };
487
468
  }
488
469
  function isCSSDefineFile(filePath, target) {
489
470
  if (fs_1.default.statSync(filePath).isDirectory())
@@ -502,8 +483,6 @@ function isCSSDefineFile(filePath, target) {
502
483
  console.log(err);
503
484
  return false;
504
485
  }
505
- if (!ast)
506
- return false;
507
486
  let found = false;
508
487
  (0, core_1.traverse)(ast, {
509
488
  CallExpression(path) {
@@ -554,10 +533,6 @@ function loader(source) {
554
533
  callback(null, source);
555
534
  return;
556
535
  }
557
- if (!ast) {
558
- callback(null, source);
559
- return;
560
- }
561
536
  const localConsts = collectLocalConsts(ast);
562
537
  Object.assign(constTable, localConsts);
563
538
  const pluginAst = {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plumeria/webpack-plugin",
3
- "version": "0.22.1",
3
+ "version": "0.22.2",
4
4
  "description": "Plumeria Webpack plugin",
5
5
  "repository": {
6
6
  "type": "git",