@blueprintui/cli 0.7.2 → 0.8.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.8.0
4
+ - add import attributes support
5
+
6
+ ## 0.7.2
7
+ - bump dependencies
8
+
3
9
  ## 0.7.1
4
10
  - bump dependencies
5
11
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueprintui/cli",
3
- "version": "0.7.2",
3
+ "version": "0.8.0",
4
4
  "description": "",
5
5
  "main": "./index.mjs",
6
6
  "bin": {
@@ -31,8 +31,8 @@
31
31
  "path": "0.12.7",
32
32
  "rollup": "4.18.0",
33
33
  "rollup-plugin-copy": "3.5.0",
34
+ "rollup-plugin-css-modules": "0.1.2",
34
35
  "rollup-plugin-delete": "2.0.0",
35
- "rollup-plugin-import-css": "3.5.0",
36
36
  "rollup-plugin-shell": "1.0.9",
37
37
  "terser": "5.31.1",
38
38
  "tslib": "2.6.3",
package/src/index.mjs CHANGED
@@ -117,10 +117,6 @@ function buildRollup(args) {
117
117
 
118
118
  try {
119
119
  watcher.on('event', (event) => {
120
- if (event.result) {
121
- event.result.watchFiles = null;
122
- }
123
-
124
120
  switch (event.code) {
125
121
  case 'START':
126
122
  console.log(status.info, 'Building...');
@@ -1,106 +1,31 @@
1
1
  import browserslist from 'browserslist';
2
- import { createFilter } from '@rollup/pluginutils';
3
2
  import { transform, browserslistToTargets } from 'lightningcss';
4
- import { path } from 'zx';
5
3
 
6
4
  const targets = browserslistToTargets(browserslist('Chrome > 116'));
7
5
 
8
- // fork of https://github.com/jleeson/rollup-plugin-import-css to enable import attributes and minificaiton
6
+ // fork of https://github.com/justinfagnani/rollup-plugin-css-modules/tree/main
9
7
  export const css = (options = {}) => {
10
- const styles = {};
11
- const filter = createFilter(
12
- options.include ?? ['**/*.css'],
13
- options.exclude ?? []
14
- );
15
-
16
- /* function to sort the css imports in order - credit to rollup-plugin-postcss */
17
- const getRecursiveImportOrder = (id, getModuleInfo, seen = new Set()) => {
18
- if (seen.has(id)) return [];
19
-
20
- seen.add(id);
21
-
22
- const result = [id];
23
-
24
- getModuleInfo(id).importedIds.forEach((importFile) => {
25
- result.push(...getRecursiveImportOrder(importFile, getModuleInfo, seen));
26
- });
27
-
28
- return result;
29
- };
30
-
31
8
  return {
32
- name: 'import-css',
33
-
34
- /* convert the css file to a module and save the code for a file output */
9
+ name: 'css-modules',
35
10
  transform(code, id) {
36
- if (!filter(id)) return;
37
-
38
- const output = options.minify
39
- ? transform({
40
- targets,
41
- drafts: {
42
- nesting: true,
43
- },
44
- analyzeDependencies: true,
45
- code: Buffer.from(code),
46
- minify: true,
47
- sourceMap: false,
48
- }).code.toString()
49
- : code;
50
-
51
- /* cache the result */
52
- if (!styles[id] || styles[id] != output) {
53
- styles[id] = output;
11
+ const isCssModule = this.getModuleInfo(id)?.attributes.type === 'css';
12
+ if (isCssModule) {
13
+ const output = options.minify
14
+ ? transform({
15
+ targets,
16
+ drafts: {
17
+ nesting: true,
18
+ },
19
+ analyzeDependencies: true,
20
+ code: Buffer.from(code),
21
+ minify: true,
22
+ sourceMap: false,
23
+ }).code.toString()
24
+ : code;
25
+
26
+ return `const stylesheet = new CSSStyleSheet();stylesheet.replaceSync(\`${output}\`);export default stylesheet;`;
54
27
  }
55
-
56
- return {
57
- code: `const sheet = new CSSStyleSheet();sheet.replaceSync(${JSON.stringify(
58
- output
59
- )});export default sheet;`,
60
- map: { mappings: '' },
61
- };
62
- },
63
-
64
- /* output a css file with all css that was imported without being assigned a variable */
65
- generateBundle(opts, bundle) {
66
- /* collect all the imported modules for each entry file */
67
- let modules = {};
68
- let entryChunk = null;
69
- for (let file in bundle) {
70
- modules = Object.assign(modules, bundle[file].modules);
71
- if (!entryChunk) entryChunk = bundle[file].facadeModuleId;
72
- }
73
-
74
- /* get the list of modules in order */
75
- const moduleIds = getRecursiveImportOrder(entryChunk, this.getModuleInfo);
76
-
77
- /* remove css that was imported as a string */
78
- const css = Object.entries(styles)
79
- .sort((a, b) => moduleIds.indexOf(a[0]) - moduleIds.indexOf(b[0]))
80
- .map(([id, code]) => {
81
- if (!modules[id]) return code;
82
- })
83
- .join('\n');
84
-
85
- /* return the asset name by going through a set of possible options */
86
- const getAssetName = () => {
87
- const fileName = options.output ?? opts.file ?? 'bundle.js';
88
- return `${path.basename(fileName, path.extname(fileName))}.css`;
89
- };
90
-
91
- /* return the asset fileName by going through a set of possible options */
92
- const getAssetFileName = () => {
93
- if (options.output) return options.output;
94
- if (opts.assetFileNames) return undefined;
95
- return `${getAssetName()}.css`;
96
- };
97
-
98
- this.emitFile({
99
- type: 'asset',
100
- name: getAssetName(),
101
- fileName: getAssetFileName(),
102
- source: css,
103
- });
28
+ return null;
104
29
  },
105
30
  };
106
31
  };
@@ -6,8 +6,6 @@ import copy from 'rollup-plugin-copy';
6
6
  import del from 'rollup-plugin-delete';
7
7
  import execute from 'rollup-plugin-shell';
8
8
  import { fs, glob, path } from 'zx';
9
- import { importAssertions } from 'acorn-import-assertions';
10
- // import { importAttributes } from 'acorn-import-attributes'; // enable when TypeScript supports import attributes
11
9
  import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
12
10
  import { fileURLToPath } from 'url';
13
11
  import { css } from './plugin-minify-css.mjs';
@@ -48,10 +46,6 @@ export default [
48
46
  sourcemap: project.sourcemap,
49
47
  sourcemapExcludeSources: true
50
48
  },
51
- acornInjectPlugins: [
52
- importAssertions
53
- // importAttributes
54
- ],
55
49
  plugins: [
56
50
  project.prod ? cleanOutDir() : [],
57
51
  css({ minify: project.prod }),