@blueprintui/cli 0.2.0 → 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/CHANGELOG.md +1 -1
- package/package.json +1 -1
- package/src/rollup.config.mjs +1 -1
- package/src/plugin-import-assert.mjs +0 -114
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/rollup.config.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { fs, glob, path } from 'zx';
|
|
|
9
9
|
import { importAssertions } from 'acorn-import-assertions';
|
|
10
10
|
import { idiomaticDecoratorsTransformer, constructorCleanupTransformer } from '@lit/ts-transformers';
|
|
11
11
|
import { fileURLToPath } from 'url';
|
|
12
|
-
import { importAssertionsPlugin } from '
|
|
12
|
+
import { importAssertionsPlugin } from 'rollup-plugin-import-assert';
|
|
13
13
|
import { minifyCSS } from './plugin-minify-css.mjs';
|
|
14
14
|
import { minifyHTML } from './plugin-minify-html-literals.mjs';
|
|
15
15
|
import { minifyJavaScript } from './plugin-minify-javascript.mjs';
|
|
@@ -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
|
-
}
|