tungsten 0.2.20 → 0.2.22
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/_client/cjsHelpers.d.ts.map +1 -1
- package/dist/_client/cjsHelpers.js +3 -0
- package/dist/bin/commands/compile.d.ts.map +1 -1
- package/dist/bin/commands/compile.js +1 -1
- package/dist/build/compileJavascript.d.ts.map +1 -1
- package/dist/build/compileJavascript.js +4 -3
- package/dist/isDev.d.ts.map +1 -1
- package/dist/isDev.js +12 -8
- package/dist/postcssPlugins/parseSelectorsRich.d.ts.map +1 -1
- package/dist/postcssPlugins/parseSelectorsRich.js +5 -4
- package/dist/postcssPlugins/parseSelectorsRich.sxyt.js +22 -0
- package/dist/settings.d.ts +1 -0
- package/dist/settings.d.ts.map +1 -1
- package/dist/settings.js +1 -0
- package/dist/style/styleContentSxy.d.ts.map +1 -1
- package/dist/style/styleContentSxy.js +7 -5
- package/dist/style/unusedStyles.d.ts +1 -3
- package/dist/style/unusedStyles.d.ts.map +1 -1
- package/dist/style/unusedStyles.js +25 -15
- package/package.json +1 -1
- package/types/index.d.ts +12 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cjsHelpers.d.ts","sourceRoot":"","sources":["../../src/_client/cjsHelpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,gBAAgB,CAAA;
|
|
1
|
+
{"version":3,"file":"cjsHelpers.d.ts","sourceRoot":"","sources":["../../src/_client/cjsHelpers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAa,MAAM,gBAAgB,CAAA;AAqCvD,OAAO,CAAC,MAAM,CAAC;IACX,UAAU,MAAM;QACZ,qBAAqB,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;YAAE,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;SAAE,CAAC,CAAA;KAC/E;CACJ;AA6BD,wBAAsB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,mCAuC5C"}
|
|
@@ -3,8 +3,11 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
|
|
|
3
3
|
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
4
4
|
// CommonJS browser packages commonly branch on process.env.NODE_ENV.
|
|
5
5
|
// Provide the minimal Node-compatible shape before any converted module runs.
|
|
6
|
+
// __tungstenCjsShim marks this as our shim and not a real node process, so that code
|
|
7
|
+
// testing for node (isDev.ts) is not fooled by it. See the Process augmentation in isDev.ts.
|
|
6
8
|
const browserGlobal = globalThis;
|
|
7
9
|
browserGlobal.process = {
|
|
10
|
+
__tungstenCjsShim: true,
|
|
8
11
|
env: {
|
|
9
12
|
NODE_ENV: 'development'
|
|
10
13
|
},
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/compile.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"compile.d.ts","sourceRoot":"","sources":["../../../src/bin/commands/compile.ts"],"names":[],"mappings":"AAgRA,OAAO,EAAE,CAAA"}
|
|
@@ -18,7 +18,7 @@ const targetOptions = {
|
|
|
18
18
|
'--public': 'public'
|
|
19
19
|
};
|
|
20
20
|
const args = process.argv.slice(3);
|
|
21
|
-
const usage = 'Usage: tungsten compile [targets] [--all] [--watch] [--no-clean] [--output <dir>]';
|
|
21
|
+
const usage = 'Usage: tungsten compile [targets] [--all] [--watch] [--no-clean] [--output <dir>]' + ' [--ready-file <file>] [--quiet] [--ignore-dirs <dir>] [--ignore-patterns <pattern>]';
|
|
22
22
|
if (args.includes('--help') || args.includes('-h')) {
|
|
23
23
|
cliOut(usage);
|
|
24
24
|
cliOut('Targets: --js, --css, --client, --assets, --public');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"compileJavascript.d.ts","sourceRoot":"","sources":["../../src/build/compileJavascript.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAO/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAetC,KAAK,uBAAuB,GAAG;IAC3B,OAAO,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IAClC,WAAW,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IACtC,aAAa,EAAE,aAAa,CAAA;IAC5B,cAAc,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACnC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,eAAe,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;CAC9F,CAAA;AAKD,wBAAsB,iBAAiB,CACnC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,uBAAuB,EACtD,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EACrE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,UAAO,EAC1E,OAAO,GAAE,wBAA6B,GACvC,OAAO,CAAC,uBAAuB,CAAC,
|
|
1
|
+
{"version":3,"file":"compileJavascript.d.ts","sourceRoot":"","sources":["../../src/build/compileJavascript.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,UAAU,CAAA;AAO/B,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAA;AACpE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AACvD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,YAAY,CAAA;AAetC,KAAK,uBAAuB,GAAG;IAC3B,OAAO,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IAClC,WAAW,EAAE,QAAQ,CAAC,SAAS,GAAG,IAAI,CAAA;IACtC,aAAa,EAAE,aAAa,CAAA;IAC5B,cAAc,EAAE,OAAO,CAAA;CAC1B,CAAA;AAED,MAAM,MAAM,0BAA0B,GAAG;IACrC,OAAO,EAAE,OAAO,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,wBAAwB,GAAG;IACnC,KAAK,CAAC,EAAE,OAAO,CAAA;IACf,qBAAqB,CAAC,EAAE,MAAM,CAAA;IAC9B,eAAe,CAAC,EAAE,CAAC,CAAC,KAAK,EAAE,0BAA0B,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,GAAG,SAAS,CAAA;CAC9F,CAAA;AAKD,wBAAsB,iBAAiB,CACnC,UAAU,EAAE,MAAM,EAAE,SAAS,EAAE,uBAAuB,EACtD,YAAY,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,EACrE,aAAa,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,UAAO,EAC1E,OAAO,GAAE,wBAA6B,GACvC,OAAO,CAAC,uBAAuB,CAAC,CA2TlC"}
|
|
@@ -148,10 +148,11 @@ export async function compileJavascript(projectDir, appConfig, codeLocation, sou
|
|
|
148
148
|
});
|
|
149
149
|
const transformResults = await Promise.allSettled(transformPromises);
|
|
150
150
|
const transformFailures = transformResults.filter(result => result.status === 'rejected').map(result => result.reason);
|
|
151
|
-
let deferredWorkPosition = 0;
|
|
152
151
|
const settleDeferredWork = async () => {
|
|
153
|
-
|
|
154
|
-
|
|
152
|
+
// splice out (rather than slice+advance-a-pointer) so settled entries are freed for GC -
|
|
153
|
+
// otherwise every package-dependency promise ever pushed stays reachable for the life of
|
|
154
|
+
// the watch process, leaking memory until it OOMs on long-running `--watch` sessions
|
|
155
|
+
const currentPromises = promises.splice(0, promises.length);
|
|
155
156
|
const deferredResults = await Promise.allSettled(currentPromises);
|
|
156
157
|
return deferredResults.filter(result => result.status === 'rejected').map(result => result.reason);
|
|
157
158
|
};
|
package/dist/isDev.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,CAAA;
|
|
1
|
+
{"version":3,"file":"isDev.d.ts","sourceRoot":"","sources":["../src/isDev.ts"],"names":[],"mappings":"AAGA,QAAA,IAAI,KAAK,SAAQ,CAAA;AAoBjB,OAAO,EAAE,KAAK,EAAE,CAAA"}
|
package/dist/isDev.js
CHANGED
|
@@ -1,18 +1,22 @@
|
|
|
1
1
|
import { TungstenError } from "./TungstenError.js";
|
|
2
2
|
let isDev = false;
|
|
3
|
-
//
|
|
4
|
-
// `process`
|
|
5
|
-
//
|
|
6
|
-
// the node branch, finds no __TUNGSTEN_ENV, and reports
|
|
7
|
-
|
|
3
|
+
// Neither global alone identifies the environment:
|
|
4
|
+
// - `process` exists in the browser in dev, because cjsHelpers.js installs a shim so that
|
|
5
|
+
// converted CJS packages can read process.env.NODE_ENV. A plain `typeof process` check
|
|
6
|
+
// therefore takes the node branch in the browser, finds no __TUNGSTEN_ENV, and reports
|
|
7
|
+
// isDev === false in dev.
|
|
8
|
+
// - `window` exists in node under the DOM test environment, so a plain `typeof window`
|
|
9
|
+
// check takes the browser branch in tests and throws on the missing __tungsten_prod__.
|
|
10
|
+
// So the shim marks itself (__tungstenCjsShim, declared in types/index.d.ts), and we exclude it.
|
|
11
|
+
if (typeof process !== 'undefined' && process.__tungstenCjsShim !== true) {
|
|
12
|
+
// server
|
|
13
|
+
isDev = process.env.__TUNGSTEN_ENV === 'development';
|
|
14
|
+
} else {
|
|
8
15
|
// browser
|
|
9
16
|
// typed as boolean, but it is set by an inline script in <head>, so it really can be
|
|
10
17
|
// missing at runtime if that script did not run
|
|
11
18
|
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
12
19
|
if (window.__tungsten_prod__ === undefined) throw new TungstenError('Err: window.__tungsten_prod__ is undefined');
|
|
13
20
|
isDev = !window.__tungsten_prod__;
|
|
14
|
-
} else {
|
|
15
|
-
// node
|
|
16
|
-
isDev = process.env.__TUNGSTEN_ENV === 'development';
|
|
17
21
|
}
|
|
18
22
|
export { isDev };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parseSelectorsRich.d.ts","sourceRoot":"","sources":["../../src/postcssPlugins/parseSelectorsRich.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG,IAAI,GAAG,OAAO,
|
|
1
|
+
{"version":3,"file":"parseSelectorsRich.d.ts","sourceRoot":"","sources":["../../src/postcssPlugins/parseSelectorsRich.ts"],"names":[],"mappings":"AAGA,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,YAAY,GAAG,SAAS,GAAG,KAAK,GAAG,IAAI,GAAG,OAAO,GACrF,cAAc,GAAG,gBAAgB,GAAG,WAAW,CAAA;AAE/C,MAAM,MAAM,QAAQ,GAAG;IACnB,IAAI,EAAE,YAAY,CAAA;IAClB,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,OAAO,CAAA;CACjB,CAAA;AAOD,wBAAgB,kBAAkB,CAAC,aAAa,EAAE,MAAM,cAqPvD"}
|
|
@@ -160,7 +160,8 @@ export function parseSelectorsRich(selectorGroup) {
|
|
|
160
160
|
// TODO -- handle pseudo with brackets
|
|
161
161
|
case 'pseudo':
|
|
162
162
|
{
|
|
163
|
-
if (/[a-zA-Z]/.test(char)) {
|
|
163
|
+
if (/[a-zA-Z-_]/.test(char)) {
|
|
164
|
+
// leading - / _ for vendor prefixes, e.g. :-moz-focusring
|
|
164
165
|
//console.log('its a pseudo class')
|
|
165
166
|
selectorObject.type = 'pseudo-class';
|
|
166
167
|
selectorObject.content += char;
|
|
@@ -169,7 +170,7 @@ export function parseSelectorsRich(selectorGroup) {
|
|
|
169
170
|
mode = 'pseudo-class';
|
|
170
171
|
pos++;
|
|
171
172
|
} else if (char === ':') {
|
|
172
|
-
selectorObject.type
|
|
173
|
+
selectorObject.type = 'pseudo-element';
|
|
173
174
|
selectorObject.content += char;
|
|
174
175
|
mode = 'pseudo-element';
|
|
175
176
|
pos++;
|
|
@@ -228,8 +229,8 @@ export function parseSelectorsRich(selectorGroup) {
|
|
|
228
229
|
{
|
|
229
230
|
if (selectorObject.content.length === 2) {
|
|
230
231
|
// first char after ::
|
|
231
|
-
if (/[a-zA-Z0-9]/.test(char)) {
|
|
232
|
-
//
|
|
232
|
+
if (/[a-zA-Z0-9-_]/.test(char)) {
|
|
233
|
+
// leading - / _ for vendor prefixes, e.g. ::-webkit-details-marker
|
|
233
234
|
selectorObject.content += char;
|
|
234
235
|
selectorObject.valid = true;
|
|
235
236
|
pos++;
|
|
@@ -28,6 +28,13 @@ function pseudoSelector(pesudo) {
|
|
|
28
28
|
valid: true
|
|
29
29
|
};
|
|
30
30
|
}
|
|
31
|
+
function pseudoElementSelector(pseudoElement) {
|
|
32
|
+
return {
|
|
33
|
+
type: 'pseudo-element',
|
|
34
|
+
content: pseudoElement,
|
|
35
|
+
valid: true
|
|
36
|
+
};
|
|
37
|
+
}
|
|
31
38
|
function attributeSelector(attribute) {
|
|
32
39
|
return {
|
|
33
40
|
type: 'attribute',
|
|
@@ -130,4 +137,19 @@ describe('parseSelectorsRich()', ({
|
|
|
130
137
|
const selectors = parseSelectorsRich(input13);
|
|
131
138
|
selectors.should.deep.equal([tagSelector('html'), whitespace(), pseudoSelector(':i(div)')]);
|
|
132
139
|
});
|
|
140
|
+
const input14 = 'summary::before';
|
|
141
|
+
it(`parses out a pseudo-element from '${input14}'`, () => {
|
|
142
|
+
const selectors = parseSelectorsRich(input14);
|
|
143
|
+
selectors.should.deep.equal([tagSelector('summary'), pseudoElementSelector('::before')]);
|
|
144
|
+
});
|
|
145
|
+
const input15 = 'summary::-webkit-details-marker';
|
|
146
|
+
it(`parses out a vendor prefixed pseudo-element from '${input15}'`, () => {
|
|
147
|
+
const selectors = parseSelectorsRich(input15);
|
|
148
|
+
selectors.should.deep.equal([tagSelector('summary'), pseudoElementSelector('::-webkit-details-marker')]);
|
|
149
|
+
});
|
|
150
|
+
const input16 = 'input:-moz-focusring';
|
|
151
|
+
it(`parses out a vendor prefixed pseudo-class from '${input16}'`, () => {
|
|
152
|
+
const selectors = parseSelectorsRich(input16);
|
|
153
|
+
selectors.should.deep.equal([tagSelector('input'), pseudoSelector(':-moz-focusring')]);
|
|
154
|
+
});
|
|
133
155
|
});
|
package/dist/settings.d.ts
CHANGED
|
@@ -16,6 +16,7 @@ export declare const assetsFolder = ".assets";
|
|
|
16
16
|
export declare const componentCssFolder = ".componentCss";
|
|
17
17
|
export declare const componentCssFile = "ccss.css";
|
|
18
18
|
export declare const packagesFolder = ".packages";
|
|
19
|
+
export declare const unusedStyleReporting: boolean;
|
|
19
20
|
export declare const packageName = "tungsten";
|
|
20
21
|
export declare const packageNameCapitalized = "Tungsten";
|
|
21
22
|
export declare const frameworkClientFolder = "_client";
|
package/dist/settings.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,cAAc,CAAA;AACtC,eAAO,MAAM,gBAAgB,SAAS,CAAA;AACtC,eAAO,MAAM,mBAAmB,kBAAuB,CAAA;AACvD,eAAO,MAAM,cAAc,uBAA+C,CAAA;AAC1E,eAAO,MAAM,eAAe,mBAAwB,CAAA;AACpD,eAAO,MAAM,mBAAmB,wBAA2C,CAAA;AAC3E,eAAO,MAAM,YAAY,2BAA+B,CAAA;AACxD,eAAO,MAAM,gBAAgB,yBAA8B,CAAA;AAC3D,eAAO,MAAM,mBAAmB,4BAAiC,CAAA;AACjE,eAAO,MAAM,qBAAqB,cAAc,CAAA;AAChD,eAAO,MAAM,YAAY,WAAW,CAAA;AAEpC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,kBAAkB,kBAAkB,CAAA;AACjD,eAAO,MAAM,gBAAgB,aAAa,CAAA;AAC1C,eAAO,MAAM,cAAc,cAAc,CAAA;AAEzC,eAAO,MAAM,WAAW,aAAa,CAAA;AACrC,eAAO,MAAM,sBAAsB,aAAa,CAAA;AAChD,eAAO,MAAM,qBAAqB,YAAY,CAAA;AAC9C,eAAO,MAAM,mBAAmB,SAAS,CAAA"}
|
|
1
|
+
{"version":3,"file":"settings.d.ts","sourceRoot":"","sources":["../src/settings.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,WAAW,cAAc,CAAA;AACtC,eAAO,MAAM,gBAAgB,SAAS,CAAA;AACtC,eAAO,MAAM,mBAAmB,kBAAuB,CAAA;AACvD,eAAO,MAAM,cAAc,uBAA+C,CAAA;AAC1E,eAAO,MAAM,eAAe,mBAAwB,CAAA;AACpD,eAAO,MAAM,mBAAmB,wBAA2C,CAAA;AAC3E,eAAO,MAAM,YAAY,2BAA+B,CAAA;AACxD,eAAO,MAAM,gBAAgB,yBAA8B,CAAA;AAC3D,eAAO,MAAM,mBAAmB,4BAAiC,CAAA;AACjE,eAAO,MAAM,qBAAqB,cAAc,CAAA;AAChD,eAAO,MAAM,YAAY,WAAW,CAAA;AAEpC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,YAAY,YAAY,CAAA;AACrC,eAAO,MAAM,kBAAkB,kBAAkB,CAAA;AACjD,eAAO,MAAM,gBAAgB,aAAa,CAAA;AAC1C,eAAO,MAAM,cAAc,cAAc,CAAA;AAEzC,eAAO,MAAM,oBAAoB,EAAE,OAAe,CAAA;AAElD,eAAO,MAAM,WAAW,aAAa,CAAA;AACrC,eAAO,MAAM,sBAAsB,aAAa,CAAA;AAChD,eAAO,MAAM,qBAAqB,YAAY,CAAA;AAC9C,eAAO,MAAM,mBAAmB,SAAS,CAAA"}
|
package/dist/settings.js
CHANGED
|
@@ -17,6 +17,7 @@ export const assetsFolder = '.assets';
|
|
|
17
17
|
export const componentCssFolder = '.componentCss';
|
|
18
18
|
export const componentCssFile = 'ccss.css';
|
|
19
19
|
export const packagesFolder = '.packages';
|
|
20
|
+
export const unusedStyleReporting = false;
|
|
20
21
|
export const packageName = 'tungsten';
|
|
21
22
|
export const packageNameCapitalized = 'Tungsten';
|
|
22
23
|
export const frameworkClientFolder = '_client';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styleContentSxy.d.ts","sourceRoot":"","sources":["../../src/style/styleContentSxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EACH,KAAK,WAAW,EACnB,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"styleContentSxy.d.ts","sourceRoot":"","sources":["../../src/style/styleContentSxy.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EACH,KAAK,WAAW,EACnB,MAAM,mBAAmB,CAAA;AAc1B,wBAAgB,eAAe,CAAC,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,eAIrE"}
|
|
@@ -5,13 +5,14 @@ import { TungstenError } from "../TungstenError.js";
|
|
|
5
5
|
import { componentBumpClass } from "../componentClassName.js";
|
|
6
6
|
import { $props, $type } from "../contentNodeSymbols.js";
|
|
7
7
|
import { isDev } from "../isDev.js";
|
|
8
|
+
import { unusedStyleReporting } from "../settings.js";
|
|
8
9
|
import { getStyleUsage } from "./unusedStyles.js";
|
|
9
10
|
function debug(...texts) {
|
|
10
11
|
//console.log(...texts)
|
|
11
12
|
}
|
|
12
13
|
export function styleContentSxy(content, styles) {
|
|
13
14
|
if (count(styles.tags) === 0 && count(styles.classes) === 0) return content; // optimization short circuit
|
|
14
|
-
processItem(content, styles, isDev ? getStyleUsage(styles) : undefined);
|
|
15
|
+
processItem(content, styles, isDev && unusedStyleReporting ? getStyleUsage(styles) : undefined);
|
|
15
16
|
return content;
|
|
16
17
|
}
|
|
17
18
|
function processItem(element, styles, usage) {
|
|
@@ -89,7 +90,7 @@ function processItem(element, styles, usage) {
|
|
|
89
90
|
}
|
|
90
91
|
}
|
|
91
92
|
debug('--tagName', tagName, element);
|
|
92
|
-
if (!Object.getOwnPropertySymbols(element).includes($props)
|
|
93
|
+
if (!Object.getOwnPropertySymbols(element).includes($props) /*|| element[$props] === undefined*/) {
|
|
93
94
|
//throw new TungstenError(`Error, element has no props. ${element}`)
|
|
94
95
|
warn(`Warning, element has no props. ${typeof element}:`, element);
|
|
95
96
|
// in one instance, the element is a function
|
|
@@ -97,8 +98,9 @@ function processItem(element, styles, usage) {
|
|
|
97
98
|
element[$props] = {};
|
|
98
99
|
}
|
|
99
100
|
let newClassName = '';
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
const tagClass = styles.tags[tagName];
|
|
102
|
+
if (tagClass !== undefined) {
|
|
103
|
+
newClassName += ' ' + componentBumpClass + ' ' + tagClass;
|
|
102
104
|
usage?.usedTags.add(tagName);
|
|
103
105
|
}
|
|
104
106
|
//console.log(element.props.className)
|
|
@@ -135,7 +137,7 @@ function processItem(element, styles, usage) {
|
|
|
135
137
|
// )
|
|
136
138
|
// }
|
|
137
139
|
function getComponentName(element) {
|
|
138
|
-
return element[$type].tagName || element[$type].constructor.name;
|
|
140
|
+
return element[$type].tagName || element[$type].constructor.name; // eslint-disable-line @typescript-eslint/strict-boolean-expressions -- has worked so far, leaving it
|
|
139
141
|
//// I don't think we have these things in our framework yet
|
|
140
142
|
// if ( element.type['$$typeof'] === Symbol.for('react.forward_ref') ) {
|
|
141
143
|
// return element.type.render.tagName || element.type.render.displayName || element.type.render.name
|
|
@@ -3,9 +3,7 @@ export type StyleUsage = {
|
|
|
3
3
|
styles: CssNames;
|
|
4
4
|
usedTags: Set<string>;
|
|
5
5
|
usedClasses: Set<string>;
|
|
6
|
-
reportedTags: Set<string>;
|
|
7
|
-
reportedClasses: Set<string>;
|
|
8
6
|
};
|
|
9
7
|
export declare function getStyleUsage(styles: CssNames): StyleUsage;
|
|
10
|
-
export declare function reportUnusedStyles(): void
|
|
8
|
+
export declare function reportUnusedStyles(): Promise<void>;
|
|
11
9
|
//# sourceMappingURL=unusedStyles.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unusedStyles.d.ts","sourceRoot":"","sources":["../../src/style/unusedStyles.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unusedStyles.d.ts","sourceRoot":"","sources":["../../src/style/unusedStyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAa9C,MAAM,MAAM,UAAU,GAAG;IACrB,MAAM,EAAE,QAAQ,CAAA;IAChB,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACrB,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAC3B,CAAA;AAUD,wBAAgB,aAAa,CAAC,MAAM,EAAE,QAAQ,cAQ7C;AA2BD,wBAAsB,kBAAkB,kBAgBvC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { warn } from "../output.js";
|
|
1
|
+
import { warn as safeWarn } from "../output.js";
|
|
2
2
|
// component stylesheets are module level singletons, so holding them here is not a leak
|
|
3
3
|
const usageByStyles = new Map();
|
|
4
4
|
// wait for render activity to settle before reporting, so that content rendered a little
|
|
5
5
|
// later (async components, route changes) doesn't get reported as unused
|
|
6
|
-
const reportDelayMs =
|
|
6
|
+
const reportDelayMs = 1000;
|
|
7
7
|
let reportHandle;
|
|
8
8
|
export function getStyleUsage(styles) {
|
|
9
9
|
let usage = usageByStyles.get(styles);
|
|
@@ -11,9 +11,7 @@ export function getStyleUsage(styles) {
|
|
|
11
11
|
usage = {
|
|
12
12
|
styles,
|
|
13
13
|
usedTags: new Set(),
|
|
14
|
-
usedClasses: new Set()
|
|
15
|
-
reportedTags: new Set(),
|
|
16
|
-
reportedClasses: new Set()
|
|
14
|
+
usedClasses: new Set()
|
|
17
15
|
};
|
|
18
16
|
usageByStyles.set(styles, usage);
|
|
19
17
|
}
|
|
@@ -26,18 +24,30 @@ function scheduleUnusedStylesReport() {
|
|
|
26
24
|
// don't hold a node process open just for the report
|
|
27
25
|
if (typeof reportHandle === 'object' && typeof reportHandle.unref === 'function') reportHandle.unref();
|
|
28
26
|
}
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
27
|
+
// cliOutput pulls in chalk, which is node only, so it must not enter the browser's module
|
|
28
|
+
// graph. A promise rather than top level await: awaiting here would make this an async
|
|
29
|
+
// module, and with it every importer of styleContentSxy.
|
|
30
|
+
// In the prod client bundle the whole conditional folds to the Promise.resolve() branch,
|
|
31
|
+
// so the import() is not emitted at all.
|
|
32
|
+
// const warnPromise: Promise<(...texts: unknown[]) => void> = (isServer)
|
|
33
|
+
// ? import('../cliOutput.js').then(module => module.cliWarn)
|
|
34
|
+
// : Promise.resolve(safeWarn)
|
|
35
|
+
const warnPromise = Promise.resolve(safeWarn);
|
|
36
|
+
// names in the stylesheet that nothing has matched, marking them so that they are only
|
|
37
|
+
// reported once. Without that, every later render repeats the same warning
|
|
38
|
+
function takeUnmatched(names, used) {
|
|
39
|
+
const unmatched = Object.keys(names).filter(name => !used.has(name));
|
|
40
|
+
for (const name of unmatched) used.add(name);
|
|
41
|
+
return unmatched;
|
|
42
|
+
}
|
|
43
|
+
export async function reportUnusedStyles() {
|
|
44
|
+
clearTimeout(reportHandle);
|
|
45
|
+
reportHandle = undefined;
|
|
46
|
+
const warn = await warnPromise;
|
|
34
47
|
for (const usage of usageByStyles.values()) {
|
|
35
|
-
const tags =
|
|
36
|
-
const classes =
|
|
48
|
+
const tags = takeUnmatched(usage.styles.tags, usage.usedTags);
|
|
49
|
+
const classes = takeUnmatched(usage.styles.classes, usage.usedClasses);
|
|
37
50
|
if (tags.length === 0 && classes.length === 0) continue;
|
|
38
|
-
// only report each selector once, otherwise every later render repeats the warning
|
|
39
|
-
for (const tag of tags) usage.reportedTags.add(tag);
|
|
40
|
-
for (const className of classes) usage.reportedClasses.add(className);
|
|
41
51
|
warn(`Tungsten dev: styles in module "${usage.styles.moduleName}" have not matched any content:` + (tags.length > 0 ? `\n tag/component names: ${tags.join(', ')}` : '') + (classes.length > 0 ? `\n class names: ${classes.join(', ')}` : ''));
|
|
42
52
|
}
|
|
43
53
|
}
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -19,6 +19,18 @@ declare global {
|
|
|
19
19
|
var tungstenPublicEnv: TungstenPublicEnv
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
//// In dev, cjsHelpers.ts installs a partial `process` on the browser global so that converted
|
|
23
|
+
//// CommonJS packages can read process.env.NODE_ENV. It flags itself with __tungstenCjsShim so
|
|
24
|
+
//// that environment checks (isDev.ts) can tell it apart from a real node process.
|
|
25
|
+
//// Never present on real node.
|
|
26
|
+
declare global {
|
|
27
|
+
namespace NodeJS {
|
|
28
|
+
interface Process {
|
|
29
|
+
__tungstenCjsShim?: true
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
|
|
23
35
|
// declare global {
|
|
24
36
|
// var __T_CurrentElement: TElement // eslint-disable-line no-var
|