@blueprintui/cli 0.1.4 → 0.2.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/.nvmrc CHANGED
@@ -1 +1 @@
1
- 18.3.0
1
+ 20.0.0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ # 0.2.1
4
+ - update CSS optimization to use lightningcss
5
+ - remove legacy Safari compatibility optimizations
6
+ - bump dependencies
7
+
3
8
  ## 0.1.4
4
9
  - bump dependencies
5
10
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blueprintui/cli",
3
- "version": "0.1.4",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "main": "./index.mjs",
6
6
  "bin": {
@@ -14,29 +14,31 @@
14
14
  "author": "Crylan Software",
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
- "@custom-elements-manifest/analyzer": "0.8.0",
17
+ "@custom-elements-manifest/analyzer": "0.8.1",
18
18
  "@lit/ts-transformers": "1.1.3",
19
- "@rollup/plugin-node-resolve": "15.0.1",
19
+ "@rollup/plugin-node-resolve": "15.0.2",
20
20
  "@rollup/plugin-replace": "5.0.2",
21
- "@rollup/plugin-typescript": "11.0.0",
21
+ "@rollup/plugin-typescript": "11.1.0",
22
22
  "@rollup/plugin-virtual": "3.0.1",
23
23
  "@skypack/package-check": "0.2.2",
24
24
  "acorn-import-assertions": "1.8.0",
25
- "commander": "10.0.0",
26
- "csso": "5.0.5",
27
- "glob": "9.3.2",
25
+ "browserslist": "4.21.5",
26
+ "commander": "10.0.1",
27
+ "lightningcss": "1.20.0",
28
+ "glob": "10.2.2",
28
29
  "minify-html-literals": "1.3.5",
29
30
  "path": "0.12.7",
30
- "rollup": "3.20.2",
31
+ "rollup": "3.21.5",
31
32
  "rollup-plugin-copy": "3.4.0",
32
33
  "rollup-plugin-delete": "2.0.0",
34
+ "rollup-plugin-import-assert": "3.0.1",
33
35
  "rollup-plugin-shell": "1.0.9",
34
- "terser": "5.16.8",
36
+ "terser": "5.17.1",
35
37
  "tslib": "2.5.0",
36
38
  "typescript": "~4.7.4",
37
- "zx": "7.2.1"
39
+ "zx": "7.2.2"
38
40
  },
39
41
  "devDependencies": {
40
- "lite-server": "^2.6.1"
42
+ "lite-server": "2.6.1"
41
43
  }
42
44
  }
@@ -0,0 +1,29 @@
1
+ import browserslist from 'browserslist';
2
+ import { transform, browserslistToTargets } from 'lightningcss';
3
+ import { path } from 'zx';
4
+
5
+ const targets = browserslistToTargets(browserslist('Chrome > 112'));
6
+
7
+ export function minifyCSS() {
8
+ return {
9
+ load(id) { return id.slice(-4) === '.css' ? this.addWatchFile(path.resolve(id)) : null },
10
+ transform: async (css, id) => {
11
+ if (id.slice(-4) === '.css') {
12
+ const code = transform({
13
+ targets,
14
+ drafts: {
15
+ nesting: true
16
+ },
17
+ analyzeDependencies: true,
18
+ code: Buffer.from(css),
19
+ minify: true,
20
+ sourceMap: false
21
+ }).code.toString()
22
+
23
+ return { code, map: { mappings: '' } };
24
+ } else {
25
+ return null;
26
+ }
27
+ }
28
+ };
29
+ };
@@ -1,4 +1,3 @@
1
- import * as csso from 'csso';
2
1
  import typescript from '@rollup/plugin-typescript';
3
2
  import nodeResolve from '@rollup/plugin-node-resolve';
4
3
  import replace from '@rollup/plugin-replace';
@@ -10,8 +9,9 @@ import { fs, glob, path } from 'zx';
10
9
  import { importAssertions } from 'acorn-import-assertions';
11
10
  import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
12
11
  import { fileURLToPath } from 'url';
12
+ import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
13
+ import { minifyCSS } from './plugin-minify-css.mjs';
13
14
  import { minifyHTML } from './plugin-minify-html-literals.mjs';
14
- import { importAssertionsPlugin } from './plugin-import-assert.mjs';
15
15
  import { minifyJavaScript } from './plugin-minify-javascript.mjs';
16
16
  import { customElementsAnalyzer } from './plugin-custom-elements-analyzer.mjs';
17
17
  import { writeCache } from './plugin-esm-cache.mjs';
@@ -33,7 +33,7 @@ const project = {
33
33
  customElementsManifestConfig: config.customElementsManifestConfig ? path.resolve(cwd, config.customElementsManifestConfig) : path.resolve(__dirname, './custom-elements-manifest.config.mjs'),
34
34
  prod: process.env.BLUEPRINTUI_BUILD === 'production',
35
35
  sourcemap: config.sourcemap
36
- }
36
+ };
37
37
 
38
38
  export default [
39
39
  {
@@ -52,17 +52,16 @@ export default [
52
52
  plugins: [
53
53
  project.prod ? cleanOutDir() : [],
54
54
  copyAssets(),
55
- project.prod ? cssOptimize() : [],
55
+ project.prod ? minifyCSS() : [],
56
56
  importAssertionsPlugin(),
57
57
  createEntrypoints(),
58
58
  nodeResolve({ exportConditions: [project.prod ? 'production' : 'development'] }),
59
59
  compileTypescript(),
60
- project.prod ? [] : typeCheck(),
60
+ typeCheck(),
61
61
  project.prod ? [] : writeCache(project),
62
62
  project.prod ? minifyHTML() : [],
63
63
  project.prod ? minifyJavaScript() : [],
64
64
  project.prod ? inlinePackageVersion() : [],
65
- project.prod ? patchSuperMinify() : [],
66
65
  project.prod ? postClean(): [],
67
66
  project.prod ? packageCheck() : [],
68
67
  project.prod ? customElementsAnalyzer(project) : [],
@@ -104,16 +103,6 @@ function inlinePackageVersion() {
104
103
  return replace({ preventAssignment: false, values: { PACKAGE_VERSION: project.packageJSON.version } });
105
104
  }
106
105
 
107
- function patchSuperMinify() {
108
- return replace({
109
- preventAssignment: false,
110
- values: {
111
- 'super(...arguments),': 'super(...arguments);',
112
- 'super(),': 'super();',
113
- }, // safari 15 and latest chromium pupeteer bug with minification optimization in terser
114
- });
115
- }
116
-
117
106
  function postClean() {
118
107
  return del({ targets: [`${project.outDir}/**/.tsbuildinfo`, `${project.outDir}/**/_virtual`], hook: 'writeBundle' });
119
108
  }
@@ -130,10 +119,3 @@ function cleanPackageJson() {
130
119
  }
131
120
  }
132
121
  }
133
-
134
- function cssOptimize() {
135
- return {
136
- load(id) { return id.slice(-4) === '.css' ? this.addWatchFile(path.resolve(id)) : null },
137
- transform: async (css, id) => id.slice(-4) === '.css' ? ({ code: csso.minify(css, { comments: false }).css, map: { mappings: '' } }) : null
138
- };
139
- };
@@ -1,114 +0,0 @@
1
- import { path } from 'zx';
2
-
3
- // temp workaround due to package "string-to-template-literal" not shipping valid esm module & not compatible to Rollup 3.x
4
-
5
- // string-to-template-literal
6
- var illegalChars = new Map();
7
- illegalChars.set('\\', '\\\\');
8
- illegalChars.set('`', '\\`');
9
- illegalChars.set('$', '\\$');
10
- function convert(s) {
11
- if (!s) {
12
- return '``';
13
- }
14
- var res = '';
15
- for (var i = 0; i < s.length; i++) {
16
- var c = s.charAt(i);
17
- res += illegalChars.get(c) || c;
18
- }
19
- return "`" + res + "`";
20
- }
21
-
22
- // rollup-plugin-import-assert
23
- function getObjects(obj, key, val) {
24
- let objects = [];
25
- for (let prop in obj) {
26
- if (!obj.hasOwnProperty(prop)) {
27
- continue;
28
- }
29
- if (typeof obj[prop] == 'object') {
30
- objects = objects.concat(getObjects(obj[prop], key, val));
31
- }
32
- else if (prop == key && obj[prop] == val || prop == key && val == '') { //
33
- objects.push(obj);
34
- }
35
- else if (obj[prop] == val && key == '') {
36
- if (objects.lastIndexOf(obj) == -1) {
37
- objects.push(obj);
38
- }
39
- }
40
- }
41
- return objects;
42
- }
43
- const assertionMap = new Map();
44
- const filePattern = /\.(js|ts|jsx|tsx)$/;
45
- const getImportPath = (id, source) => path.resolve(path.dirname(id), source);
46
- export function importAssertionsPlugin() {
47
- return {
48
- name: 'rollup-plugin-import-assert',
49
- transform(data, id) {
50
- let code = data;
51
- /** If the file is a JS-like file, continue */
52
- if (filePattern.exec(id)) {
53
- /** Get the AST data, must be using acorn-import-assertions for this to work */
54
- const ast = this.parse(data);
55
- /** @ts-ignore this does exist apparently */
56
- const { body } = ast;
57
- const importDeclarations = getObjects(body, 'type', 'ImportDeclaration');
58
- const importExpressions = getObjects(body, 'type', 'ImportExpression');
59
- importDeclarations.forEach(node => {
60
- if (node.assertions) {
61
- const [assertion] = node.assertions;
62
- const assert = { type: assertion.value.value };
63
- const importPath = getImportPath(id, node.source.value);
64
- assertionMap.set(importPath, assert);
65
- }
66
- });
67
- importExpressions.forEach(node => {
68
- // Skip dynamic imports with expressions
69
- // @example: import(`./foo/${bar}.js`); // NOK
70
- // @example: import(`./foo/bar.js`); // OK
71
- if (node.source.type === "TemplateLiteral" && node.source.quasis.length > 1) {
72
- return;
73
- }
74
- // @example: `import(foo);` NOK
75
- if (!node.source.value)
76
- return;
77
- const source = node.source.value || node.source.quasis[0].value.raw;
78
- const importPath = getImportPath(id, source);
79
- // TODO: We can still make this better
80
- if (node.hasOwnProperty('arguments') && getObjects(node, 'name', 'assert')) {
81
- const assert = { type: node.arguments[0].properties[0]?.value?.properties[0].value.value };
82
- assertionMap.set(importPath, assert);
83
- const matches = code.match(/import\(.*\)/gi);
84
- const replacements = matches.map(match => match.replace(/\{(\s?)assert:(\s?)\{.*\}/gi, ''));
85
- if (matches) {
86
- matches.forEach((match, index) => code = code.replace(match, replacements[index]));
87
- code.match(/import\(.*(\s?),(\s?)\)/gi).forEach(match => {
88
- code = code.replace(match, match.replace(',', ''));
89
- });
90
- }
91
- }
92
- });
93
- }
94
- const assertion = assertionMap.get(id);
95
- /** If an import assertion exists for the file, parse it differently */
96
- if (assertion) {
97
- const { type } = assertion;
98
- let code = data;
99
- if (type === 'css') {
100
- /** Parse files asserted as CSS to use constructible stylesheets */
101
- code = `const sheet = new CSSStyleSheet();sheet.replaceSync(${convert(data)});export default sheet;`;
102
- }
103
- else if (type === 'json') {
104
- /** Parse files asserted as JSON as a JS object */
105
- code = `export default ${data}`;
106
- }
107
- /** Return the new data and map it back to the original source file */
108
- return { code, mappings: id };
109
- }
110
- /** If none of the above exists, just continue as normal */
111
- return { code };
112
- }
113
- };
114
- }