Comparing version 1.4.33 to 1.4.34
export declare const minifyScripts: (props: { | ||
files: Array<string>; | ||
files: Map<string, string>; | ||
cssKey: string; | ||
dest: string; | ||
}) => Promise<void>; |
import type { ScriptData } from './types'; | ||
export declare const minifyScriptForCSS: ([file, data]: [string, ScriptData]) => Promise<string>; | ||
export declare const minifyScriptsForCSS: (props: { | ||
files: Array<string>; | ||
files: Map<string, string>; | ||
cssKey: string; | ||
dest: string; | ||
}) => Promise<void>; |
@@ -22,9 +22,3 @@ "use strict"; | ||
const parseResult = await (0, parseScripts_1.parseScripts)(props); | ||
const cssList = []; | ||
for (const script of parseResult.scripts) { | ||
const css = await (0, exports.minifyScriptForCSS)(script).catch((error) => { | ||
throw error; | ||
}); | ||
cssList.push(css); | ||
} | ||
const cssList = await Promise.all([...parseResult.scripts].map(exports.minifyScriptForCSS)); | ||
await (0, updateFile_1.updateFile)(props.dest, cssList.join('\n')); | ||
@@ -31,0 +25,0 @@ }; |
import type { ParseScriptsResult } from './types'; | ||
export declare const parseScripts: ({ files, cssKey }: { | ||
files: Array<string>; | ||
files: Map<string, string>; | ||
cssKey: string; | ||
}) => Promise<ParseScriptsResult>; |
@@ -7,9 +7,19 @@ "use strict"; | ||
const tokenizeString_1 = require("../util/tokenizeString"); | ||
const { readFile } = fs.promises; | ||
const cache = new Map(); | ||
const parseScripts = async ({ files, cssKey }) => { | ||
const scripts = new Map(); | ||
const tokens = new Map(); | ||
await Promise.all(files.map(async (file) => { | ||
const code = await readFile(file, 'utf8'); | ||
const data = (0, parseCSSModuleScript_1.parseCSSModuleScript)({ code, cssKey }); | ||
const tasks = []; | ||
for (const [source, file] of files) { | ||
const { mtimeMs } = await fs.promises.stat(source); | ||
let cached = cache.get(source); | ||
if (cached && mtimeMs !== cached.mtimeMs) { | ||
cached = undefined; | ||
} | ||
let data = cached && cached.data; | ||
const code = await fs.promises.readFile(file, 'utf8'); | ||
if (!data) { | ||
data = (0, parseCSSModuleScript_1.parseCSSModuleScript)({ code, cssKey }); | ||
cache.set(source, { mtimeMs, data }); | ||
} | ||
for (const { css } of data.ranges) { | ||
@@ -21,3 +31,4 @@ for (const token of (0, tokenizeString_1.tokenizeString)(css)) { | ||
scripts.set(file, { ...data, script: code }); | ||
})); | ||
} | ||
await Promise.all(tasks); | ||
return { scripts, tokens }; | ||
@@ -24,0 +35,0 @@ }; |
@@ -58,4 +58,3 @@ "use strict"; | ||
file: filePath, | ||
}) | ||
.catch((error) => { | ||
}).catch((error) => { | ||
exposedPromise.resolve(); | ||
@@ -81,3 +80,3 @@ throw error; | ||
async minifyScripts() { | ||
const files = [...this.processedFiles].map((file) => `${file}${this.configuration.ext}`); | ||
const files = new Map([...this.processedFiles].map((file) => [file, `${file}${this.configuration.ext}`])); | ||
const { cssKey, output } = this.configuration; | ||
@@ -84,0 +83,0 @@ if (output.type === 'css') { |
@@ -292,3 +292,3 @@ "use strict"; | ||
await (0, updateFile_1.updateFile)(cssPath, [ | ||
'@keyframes foo {0%{color:red}100%{color:green}}', | ||
'@keyframes foo {0%{color:gold}100%{color:green}}', | ||
'.foo#bar {animation: 1s 0.5s linear infinite foo}', | ||
@@ -300,3 +300,3 @@ ].join('')); | ||
await (0, updateFile_1.updateFile)(cssPath, [ | ||
'@keyframes foo {0%{color:red}100%{color:green}}', | ||
'@keyframes foo {0%{color:gold}100%{color:green}}', | ||
'.foo#bar {animation: 2s 1s linear infinite foo}', | ||
@@ -338,3 +338,4 @@ ].join('')); | ||
test('watch-css', async (t) => { | ||
const cssPath = path.join(t.context.directory, '/components/style.css'); | ||
const cssPath1 = path.join(t.context.directory, '/components/style1.css'); | ||
const cssPath2 = path.join(t.context.directory, '/components/style2.css'); | ||
const cssOutputPath = path.join(t.context.directory, 'output.css'); | ||
@@ -357,18 +358,43 @@ const { messageListener, waitForMessage } = createMessageListener(); | ||
}); | ||
await (0, updateFile_1.updateFile)(cssPath, [ | ||
'@keyframes foo {0%{color:red}100%{color:green}}', | ||
'.foo#bar {animation: 1s 0.5s linear infinite foo}', | ||
await (0, updateFile_1.updateFile)(cssPath1, [ | ||
'@keyframes foo1 {0%{color:gold}100%{color:green}}', | ||
'.foo1#bar {animation: 1s 0.5s linear infinite foo1}', | ||
].join('')); | ||
await (0, updateFile_1.updateFile)(cssPath2, [ | ||
'@keyframes foo2 {0%{color:gold}100%{color:pink}}', | ||
'.foo2#bar {animation: 1s 0.5s linear infinite foo2}', | ||
].join('')); | ||
await t.context.session.start().catch(t.fail); | ||
const outputCss1 = await fs.promises.readFile(cssOutputPath, 'utf-8'); | ||
await (0, updateFile_1.updateFile)(cssPath, [ | ||
'@keyframes foo {0%{color:red}100%{color:green}}', | ||
'.foo#bar {animation: 2s 1s linear infinite foo}', | ||
t.log('outputCss1', outputCss1); | ||
t.true(outputCss1.includes('color:green')); | ||
t.true(outputCss1.includes('color:pink')); | ||
const root1 = postcss.parse(outputCss1); | ||
t.is(root1.nodes.length, 4); | ||
await (0, updateFile_1.updateFile)(cssPath1, [ | ||
'@keyframes bar1 {0%{color:gold}100%{color:blue}}', | ||
'.bar1#bar {animation: 2s 1s linear infinite bar1}', | ||
].join('')); | ||
await waitForMessage(`written: ${cssOutputPath}`); | ||
const outputCss2 = await fs.promises.readFile(cssOutputPath, 'utf-8'); | ||
t.log('outputCss1', outputCss1); | ||
t.log('outputCss2', outputCss2); | ||
t.true(outputCss1 !== outputCss2); | ||
t.false(outputCss2.includes('color:green')); | ||
t.true(outputCss2.includes('color:blue')); | ||
t.true(outputCss2.includes('color:pink')); | ||
const root2 = postcss.parse(outputCss2); | ||
t.is(root2.nodes.length, 4); | ||
await (0, updateFile_1.updateFile)(cssPath2, [ | ||
'@keyframes bar2 {0%{color:gold}100%{color:red}}', | ||
'.bar2#bar {animation: 1s 0.5s linear infinite bar2}', | ||
].join('')); | ||
await waitForMessage(`written: ${cssOutputPath}`); | ||
const outputCss3 = await fs.promises.readFile(cssOutputPath, 'utf-8'); | ||
t.log('outputCss3', outputCss3); | ||
t.false(outputCss3.includes('color:green')); | ||
t.false(outputCss3.includes('color:pink')); | ||
t.true(outputCss3.includes('color:blue')); | ||
t.true(outputCss3.includes('color:red')); | ||
const root3 = postcss.parse(outputCss3); | ||
t.is(root3.nodes.length, 4); | ||
}); | ||
//# sourceMappingURL=Session.test.js.map |
declare type Resolve = () => void; | ||
declare type Reject = (error: Error) => void; | ||
declare type Reject = (error: unknown) => void; | ||
export interface ExposedPromise { | ||
@@ -4,0 +4,0 @@ readonly promise: Promise<void>; |
{ | ||
"name": "esifycss", | ||
"version": "1.4.33", | ||
"version": "1.4.34", | ||
"description": "Generates .js or .ts exports class names and custom properties", | ||
@@ -53,11 +53,11 @@ "author": { | ||
"dependencies": { | ||
"@hookun/parse-animation-shorthand": "^0.1.2", | ||
"acorn": "^8.5.0", | ||
"acorn-walk": "^8.2.0", | ||
"chokidar": "^3.5.2", | ||
"commander": "^8.1.0", | ||
"postcss": "^8.3.6", | ||
"postcss-selector-parser": "^6.0.6", | ||
"vlq": "^1.0.1" | ||
"@hookun/parse-animation-shorthand": "0.1.2", | ||
"acorn": "8.5.0", | ||
"acorn-walk": "8.2.0", | ||
"chokidar": "3.5.2", | ||
"commander": "8.2.0", | ||
"postcss": "8.3.7", | ||
"postcss-selector-parser": "6.0.6", | ||
"vlq": "1.0.1" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Deprecated
MaintenanceThe maintainer of the package marked it as deprecated. This could indicate that a single version should not be used, or that the package is no longer maintained and any new vulnerabilities will not be fixed.
Found 1 instance in 1 package
236633
3131
1
+ Added@hookun/parse-animation-shorthand@0.1.2(transitive)
+ Addedacorn@8.5.0(transitive)
+ Addedacorn-walk@8.2.0(transitive)
+ Addedchokidar@3.5.2(transitive)
+ Addedcommander@8.2.0(transitive)
+ Addednanocolors@0.1.12(transitive)
+ Addedpostcss@8.3.7(transitive)
+ Addedpostcss-selector-parser@6.0.6(transitive)
+ Addedsource-map-js@0.6.2(transitive)
- Removed@hookun/parse-animation-shorthand@0.1.5(transitive)
- Removedacorn@8.14.0(transitive)
- Removedacorn-walk@8.3.4(transitive)
- Removedchokidar@3.6.0(transitive)
- Removedcommander@8.3.0(transitive)
- Removedpicocolors@1.1.1(transitive)
- Removedpostcss@8.5.3(transitive)
- Removedpostcss-selector-parser@6.1.2(transitive)
- Removedsource-map-js@1.2.1(transitive)
Updatedacorn@8.5.0
Updatedacorn-walk@8.2.0
Updatedchokidar@3.5.2
Updatedcommander@8.2.0
Updatedpostcss@8.3.7
Updatedvlq@1.0.1