diff --git a/package-lock.json b/package-lock.json index 8832bf4405..252eded8a3 100644 --- a/package-lock.json +++ b/package-lock.json @@ -57,6 +57,7 @@ "playwright-chromium": "^1.46.1", "playwright-core": "^1.46.1", "postcss": "^8.4.41", + "prettier": "^3.3.3", "promise-assist": "^2.0.1", "raw-loader": "^4.0.2", "react": "^18.3.1", @@ -6411,6 +6412,22 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, "node_modules/pretty-error": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/pretty-error/-/pretty-error-4.0.0.tgz", diff --git a/package.json b/package.json index 4b93d222ef..ac34b3a401 100644 --- a/package.json +++ b/package.json @@ -65,6 +65,7 @@ "playwright-chromium": "^1.46.1", "playwright-core": "^1.46.1", "postcss": "^8.4.41", + "prettier": "^3.3.3", "promise-assist": "^2.0.1", "raw-loader": "^4.0.2", "react": "^18.3.1", diff --git a/packages/build-tools/src/calc-depth.ts b/packages/build-tools/src/calc-depth.ts index 91ac786141..7e9da14988 100644 --- a/packages/build-tools/src/calc-depth.ts +++ b/packages/build-tools/src/calc-depth.ts @@ -9,7 +9,7 @@ export function calcDepth( module: T, context: CalcDepthContext, path: T[] = [], - cache = new Map() + cache = new Map(), ): number { let cssDepth = 0; if (cache.has(module)) { @@ -57,7 +57,7 @@ export function getCSSViewModule(module: T, context: CalcDepthContext) { if (parentViewsList.length > 1) { throw new Error( - `Stylable Component Conflict:\n${module} has multiple components entries [${parentViewsList}] ` + `Stylable Component Conflict:\n${module} has multiple components entries [${parentViewsList}] `, ); } return parentViewsList[0]; diff --git a/packages/build-tools/src/has-imported-side-effects.ts b/packages/build-tools/src/has-imported-side-effects.ts index 9d0584f59f..8f0f5c8ec7 100644 --- a/packages/build-tools/src/has-imported-side-effects.ts +++ b/packages/build-tools/src/has-imported-side-effects.ts @@ -10,7 +10,7 @@ export function collectImportsWithSideEffects( stylable: Stylable, meta: StylableMeta, visit: (contextMeta: StylableMeta, absPath: string, hasSideEffects: boolean) => void, - visited: Set = new Set() + visited: Set = new Set(), ) { for (const importData of meta.getImportStatements()) { // attempt to resolve the request through stylable resolveModule, @@ -19,7 +19,7 @@ export function collectImportsWithSideEffects( try { resolvedImportPath = stylable.resolver.resolvePath( importData.context, - importData.request + importData.request, ); } catch { // fallback to request // TODO: check if this is correct @@ -113,7 +113,7 @@ export function hasImportedSideEffects(stylable: Stylable, meta: StylableMeta, i ) { const cssResolved = stylable.resolver.resolveSymbolOrigin( localSymbol['-st-extends'], - meta + meta, ); if ( cssResolved?.symbol && diff --git a/packages/build-tools/src/load-stylable-config.ts b/packages/build-tools/src/load-stylable-config.ts index 59ca1faaf3..730f3cf21e 100644 --- a/packages/build-tools/src/load-stylable-config.ts +++ b/packages/build-tools/src/load-stylable-config.ts @@ -3,7 +3,7 @@ import { pathToFileURL } from 'url'; export function loadStylableConfig( context: string, - extract: (config: any) => T + extract: (config: any) => T, ): { path: string; config: T } | undefined { const path = findConfig('stylable.config.js', { cwd: context }) ?? @@ -14,12 +14,12 @@ export function loadStylableConfig( config = require(path); } catch (e) { throw new Error( - `Failed to load "stylable.config.js" from ${path}\n${(e as Error)?.stack}` + `Failed to load "stylable.config.js" from ${path}\n${(e as Error)?.stack}`, ); } if (!config) { throw new Error( - `Stylable configuration loaded from ${path} but no exported configuration found` + `Stylable configuration loaded from ${path} but no exported configuration found`, ); } return { @@ -36,7 +36,7 @@ const esmImport: (url: URL) => any = eval(`(path) => import(path)`); export async function loadStylableConfigEsm( context: string, - extract: (config: any) => T + extract: (config: any) => T, ): Promise<{ path: string; config: T } | undefined> { const path = findConfig('stylable.config.js', { cwd: context }) ?? @@ -47,12 +47,12 @@ export async function loadStylableConfigEsm( config = await esmImport(pathToFileURL(path)); } catch (e) { throw new Error( - `Failed to load "stylable.config.js" from ${path}\n${(e as Error)?.stack}` + `Failed to load "stylable.config.js" from ${path}\n${(e as Error)?.stack}`, ); } if (!config) { throw new Error( - `Stylable configuration loaded from ${path} but no exported configuration found` + `Stylable configuration loaded from ${path} but no exported configuration found`, ); } return { diff --git a/packages/build-tools/src/process-url-dependencies.ts b/packages/build-tools/src/process-url-dependencies.ts index 83444e3b07..542c4b2636 100644 --- a/packages/build-tools/src/process-url-dependencies.ts +++ b/packages/build-tools/src/process-url-dependencies.ts @@ -66,7 +66,7 @@ export function processUrlDependencies({ onUrl(functionNode); } }, - true + true, ); }); return urls; diff --git a/packages/build-tools/src/sort-modules-by-depth.ts b/packages/build-tools/src/sort-modules-by-depth.ts index 34b307705e..3f8e8c6c8f 100644 --- a/packages/build-tools/src/sort-modules-by-depth.ts +++ b/packages/build-tools/src/sort-modules-by-depth.ts @@ -5,7 +5,7 @@ export function sortModulesByDepth( modules: Array, getDepth: (m: T) => number, getID: (m: T) => string, - factor = 1 + factor = 1, ) { return modules.sort((m1, m2) => { const depthDiff = getDepth(m2) - getDepth(m1); diff --git a/packages/build-tools/test/sort-modules-by-depth.spec.ts b/packages/build-tools/test/sort-modules-by-depth.spec.ts index 25c02fe6e9..9dca09c4bd 100644 --- a/packages/build-tools/test/sort-modules-by-depth.spec.ts +++ b/packages/build-tools/test/sort-modules-by-depth.spec.ts @@ -11,7 +11,7 @@ describe('sort-modules-by-depth', () => { { id: 'a1', depth: 1 }, ], ({ depth }) => depth, - ({ id }) => id + ({ id }) => id, ); expect(sorted).to.eql([ @@ -31,7 +31,7 @@ describe('sort-modules-by-depth', () => { { id: 'a1', depth: 1 }, ], ({ depth }) => depth, - ({ id }) => id + ({ id }) => id, ); expect(sorted).to.eql([ @@ -51,7 +51,7 @@ describe('sort-modules-by-depth', () => { { id: 'a0', depth: 0 }, ], ({ depth }) => depth, - ({ id }) => id + ({ id }) => id, ); expect(sorted).to.eql([ @@ -72,7 +72,7 @@ describe('sort-modules-by-depth', () => { ], ({ depth }) => depth, ({ id }) => id, - -1 + -1, ); expect(sorted).to.eql([ diff --git a/packages/cli/src/base-generator.ts b/packages/cli/src/base-generator.ts index 5c4d95790f..69557f0393 100644 --- a/packages/cli/src/base-generator.ts +++ b/packages/cli/src/base-generator.ts @@ -56,16 +56,18 @@ export class IndexGenerator { this.log('[Generator Index]', `Add file: ${filePath}`); this.indexFileOutput.set( normalizeRelative( - this.fs.relative(this.fs.dirname(this.indexFileTargetPath), filePath) + this.fs.relative(this.fs.dirname(this.indexFileTargetPath), filePath), ), - reExports + reExports, ); } } public removeEntryFromIndex(filePath: string) { this.indexFileOutput.delete( - normalizeRelative(this.fs.relative(this.fs.dirname(this.indexFileTargetPath), filePath)) + normalizeRelative( + this.fs.relative(this.fs.dirname(this.indexFileTargetPath), filePath), + ), ); } @@ -75,7 +77,7 @@ export class IndexGenerator { await tryRun( () => fs.promises.writeFile(this.indexFileTargetPath, '\n' + indexFileContent + '\n'), - 'Write Index File Error' + 'Write Index File Error', ); this.log('[Generator Index]', 'creating index file: ' + this.indexFileTargetPath); @@ -137,14 +139,14 @@ export function reExportsAllSymbols(filePath: string, generator: IndexGenerator) acc[name] = `${rootExport}__${name}`; return acc; }, - {} + {}, ); const vars = Object.keys(STSymbol.getAllByType(meta, `cssVar`)).reduce>( (acc, varName) => { acc[varName] = `--${rootExport}__${varName.slice(2)}`; return acc; }, - {} + {}, ); const keyframes = Object.keys(STSymbol.getAllByType(meta, `keyframes`)).reduce< Record diff --git a/packages/cli/src/build-single-file.ts b/packages/cli/src/build-single-file.ts index a4981ec0d3..0c51d9e2ce 100644 --- a/packages/cli/src/build-single-file.ts +++ b/packages/cli/src/build-single-file.ts @@ -88,11 +88,11 @@ export function buildSingleFile({ let content: string = tryRun( () => fs.readFileSync(filePath, 'utf8'), - `Read File Error: ${filePath}` + `Read File Error: ${filePath}`, ); const res = tryRun( () => stylable.transform(stylable.analyze(filePath)), - errorMessages.STYLABLE_PROCESS(filePath) + errorMessages.STYLABLE_PROCESS(filePath), ); const optimizer = new StylableOptimizer(); @@ -105,7 +105,7 @@ export function buildSingleFile({ removeUnusedComponents: false, }, res, - {} + {}, ); } @@ -129,7 +129,7 @@ export function buildSingleFile({ if (useNamespaceReference && !content.includes('st-namespace-reference')) { const relativePathToSource = relative(dirname(targetFilePath), filePath).replace( /\\/gm, - '/' + '/', ); const srcNamespaceAnnotation = `\n/* st-namespace-reference="${relativePathToSource}" */`; content += srcNamespaceAnnotation; @@ -138,14 +138,14 @@ export function buildSingleFile({ outputLogs.push(`.st.css source`); tryRun( () => fs.writeFileSync(targetFilePath, content), - `Write File Error: ${targetFilePath}` + `Write File Error: ${targetFilePath}`, ); } // st.css.js const ast = includeCSSInJS ? tryRun( () => inlineAssetsForJsModule(res, stylable, fs), - `Inline assets failed for: ${filePath}` + `Inline assets failed for: ${filePath}`, ) : res.meta.targetAst!; @@ -174,7 +174,7 @@ export function buildSingleFile({ id: res.meta.namespace, runtimeId: format, } - : undefined + : undefined, ); const outFilePath = targetFilePath + ext; generated.add(outFilePath); @@ -190,7 +190,7 @@ export function buildSingleFile({ outputLogs.push('transpiled css'); tryRun( () => fs.writeFileSync(cssAssetOutPath, cssCode), - `Write File Error: ${cssAssetOutPath}` + `Write File Error: ${cssAssetOutPath}`, ); } // .d.ts @@ -289,7 +289,7 @@ export function buildDTS({ outputLogs.push('output .d.ts'); tryRun( () => mkdirSync?.(dirname(dtsPath), { recursive: true }), - `Ensure directory: ${dirname(dtsPath)}` + `Ensure directory: ${dirname(dtsPath)}`, ); tryRun(() => writeFileSync(dtsPath, dtsContent), `Write File Error: ${dtsPath}`); @@ -298,7 +298,7 @@ export function buildDTS({ if (dtsSourceMap !== false) { const relativeTargetFilePath = relative( dirname(targetFilePath), - sourceFilePath || targetFilePath + sourceFilePath || targetFilePath, ); const dtsMappingContent = generateDTSSourceMap( @@ -307,7 +307,7 @@ export function buildDTS({ // `relativeTargetFilePath` could be an absolute path in windows (e.g. unc path) isAbsolute(relativeTargetFilePath) ? relativeTargetFilePath - : relativeTargetFilePath.replace(/\\/g, '/') + : relativeTargetFilePath.replace(/\\/g, '/'), ); const dtsMapPath = targetFilePath + '.d.ts.map'; @@ -317,7 +317,7 @@ export function buildDTS({ tryRun( () => writeFileSync(dtsMapPath, dtsMappingContent), - `Write File Error: ${dtsMapPath}` + `Write File Error: ${dtsMapPath}`, ); } } diff --git a/packages/cli/src/build-stylable.ts b/packages/cli/src/build-stylable.ts index 591e49d2cc..be40eff651 100644 --- a/packages/cli/src/build-stylable.ts +++ b/packages/cli/src/build-stylable.ts @@ -54,7 +54,7 @@ export async function buildStylable( resolveModule, configFilePath, watchOptions = {}, - }: BuildStylableContext = {} + }: BuildStylableContext = {}, ) { const { config } = resolveConfig(rootDir, fs, configFilePath) || {}; validateDefaultConfig(config?.defaultConfig); @@ -76,7 +76,7 @@ export async function buildStylable( projectRoot, i, options.length > 1, - projects.length > 1 + projects.length > 1, ); log('[Project]', projectRoot, buildOptions); @@ -84,7 +84,7 @@ export async function buildStylable( if (!hasStylableCSSOutput(buildOptions)) { log( `No target output declared for "${identifier}", please provide one or more of the following target options: "cjs", "esm", "css", "stcss" or "indexFile"`, - levels.info + levels.info, ); } diff --git a/packages/cli/src/build.ts b/packages/cli/src/build.ts index 689a79ea55..b5346c797a 100644 --- a/packages/cli/src/build.ts +++ b/packages/cli/src/build.ts @@ -53,7 +53,7 @@ export async function build( log, outputFiles = new Map(), diagnosticsManager = new DiagnosticsManager({ log }), - }: BuildContext + }: BuildContext, ) { const { join, realpathSync, relative, dirname } = fs; const projectRoot = realpathSync(_projectRoot); @@ -84,7 +84,7 @@ export async function build( esm, runtimeCjsRequest, runtimeEsmRequest, - fs + fs, ); const service = new DirectoryProcessService(fs, { @@ -159,7 +159,7 @@ export async function build( if (indexFileGenerator) { indexFileGenerator.removeEntryFromIndex( - outputSources ? targetFilePath : deletedFile + outputSources ? targetFilePath : deletedFile, ); } } @@ -182,7 +182,7 @@ export async function build( // map st output file path to src file path outputFiles.set( join(fullOutDir, relative(fullSrcDir, filePath)), - new Set([filePath]) + new Set([filePath]), ); // remove assets from the affected files (handled in buildAggregatedEntities) @@ -228,8 +228,8 @@ export async function build( mode, buildMessages.FINISHED_PROCESSING( count, - isMultiPackagesProject ? identifier : undefined - ) + isMultiPackagesProject ? identifier : undefined, + ), ); } @@ -283,7 +283,7 @@ export async function build( './' + relative(dirname(targetFilePath), runtimeCjsOutPath).replace( /\\/g, - '/' + '/', ) ); } @@ -292,7 +292,7 @@ export async function build( './' + relative(dirname(targetFilePath), runtimeEsmOutPath).replace( /\\/g, - '/' + '/', ) ); } @@ -310,7 +310,7 @@ export async function build( if (indexFileGenerator) { indexFileGenerator.generateFileIndexEntry( - outputSources ? targetFilePath : filePath + outputSources ? targetFilePath : filePath, ); } } catch (error) { @@ -325,7 +325,7 @@ export async function build( sourceFiles.add(filePath); const meta = tryRun( () => stylable.analyze(filePath), - errorMessages.STYLABLE_PROCESS(filePath) + errorMessages.STYLABLE_PROCESS(filePath), ); // todo: consider merging this API with stylable.getDependencies() for (const depFilePath of tryCollectImportsDeep(stylable.resolver, meta)) { @@ -412,7 +412,7 @@ function bundleFiles({ (m) => { return m; }, - -1 /** PRINT_ORDER */ + -1 /** PRINT_ORDER */, ); const cssBundleCode = sortedModules .map((m) => { @@ -441,7 +441,7 @@ function copyRuntime( esm: boolean | undefined, runtimeCjsRequest: string, runtimeEsmRequest: string, - fs: BuildContext['fs'] + fs: BuildContext['fs'], ) { let runtimeCjsOutPath; let runtimeEsmOutPath; @@ -474,7 +474,7 @@ function resolveRequestInContext(fs: IFileSystem, request: string, projectRoot: export function createGenerator( root: string, - generatorPath?: string + generatorPath?: string, ): undefined | typeof BaseIndexGenerator { if (!generatorPath) { return undefined; diff --git a/packages/cli/src/cli-codemod.ts b/packages/cli/src/cli-codemod.ts index c0690bf965..14458856ce 100644 --- a/packages/cli/src/cli-codemod.ts +++ b/packages/cli/src/cli-codemod.ts @@ -57,7 +57,7 @@ for (const request of requires) { const log = createLogger( (_, ...messages) => console.log('[CodeMod]', ...messages), - () => console.clear() + () => console.clear(), ); const loadedMods = new Set<{ id: string; apply: CodeMod }>(); diff --git a/packages/cli/src/cli.ts b/packages/cli/src/cli.ts index b4057586c0..39125af01b 100644 --- a/packages/cli/src/cli.ts +++ b/packages/cli/src/cli.ts @@ -18,9 +18,11 @@ async function main() { const rootDir = resolve(argv.rootDir); const explicitResolveNs = namespaceResolver && - require(require.resolve(namespaceResolver, { - paths: [rootDir], - })); + require( + require.resolve(namespaceResolver, { + paths: [rootDir], + }), + ); // const log = createLogger( @@ -30,7 +32,7 @@ async function main() { console.log('[Stylable]', `[${currentTime}]`, ...messages); } }, - () => !shouldLog && !preserveWatchOutput && console.clear() + () => !shouldLog && !preserveWatchOutput && console.clear(), ); // execute all require hooks before running the CLI build diff --git a/packages/cli/src/code-format.ts b/packages/cli/src/code-format.ts index 343e9a935a..477c00788f 100644 --- a/packages/cli/src/code-format.ts +++ b/packages/cli/src/code-format.ts @@ -120,7 +120,7 @@ const { const log = createLogger( (_, ...messages) => console.log('[Stylable code formatter]', ...messages), - () => console.clear() + () => console.clear(), ); if (debug) { @@ -169,7 +169,7 @@ function formatStylesheet(filePath: string) { newline_between_rules: newlineBetweenRules, preserve_newlines: perserveNewlines, selector_separator_newline: selectorSeparatorNewline, - } + }, ); if (newText.length) { diff --git a/packages/cli/src/code-mods/apply-code-mods.ts b/packages/cli/src/code-mods/apply-code-mods.ts index d85d0e0a07..0d93bfc903 100644 --- a/packages/cli/src/code-mods/apply-code-mods.ts +++ b/packages/cli/src/code-mods/apply-code-mods.ts @@ -5,7 +5,7 @@ import type { CodeMod, ApplyCodeModsResult } from './types'; export function applyCodeMods( filePath: string, css: string, - mods: Set<{ id: string; apply: CodeMod }> + mods: Set<{ id: string; apply: CodeMod }>, ): ApplyCodeModsResult { try { const reports = new Map(); diff --git a/packages/cli/src/code-mods/code-mods.ts b/packages/cli/src/code-mods/code-mods.ts index 49780bef41..23b1183eb2 100644 --- a/packages/cli/src/code-mods/code-mods.ts +++ b/packages/cli/src/code-mods/code-mods.ts @@ -24,7 +24,7 @@ export function codeMods({ fs, rootDir, extension, mods, log }: CodeModsOptions) relative, rootDir, extension, - new Set(['node_modules', '.git']) + new Set(['node_modules', '.git']), ); if (files.size === 0) { diff --git a/packages/cli/src/code-mods/load-codemods.ts b/packages/cli/src/code-mods/load-codemods.ts index b62803e16a..604deb2b67 100644 --- a/packages/cli/src/code-mods/load-codemods.ts +++ b/packages/cli/src/code-mods/load-codemods.ts @@ -15,7 +15,7 @@ export const registeredMods: Map = new Map([ export function loadBuiltInCodemods( mods: string[], loadedMods: Set<{ id: string; apply: CodeMod }>, - log: Log + log: Log, ) { for (const id of mods) { const apply = registeredMods.get(id); @@ -31,7 +31,7 @@ export function loadExternalCodemods( external: string[], rootDir: string, loadedMods: Set<{ id: string; apply: CodeMod }>, - log: Log + log: Log, ) { for (const externalMod of external) { try { @@ -47,15 +47,15 @@ export function loadExternalCodemods( } else { throw new Error( `Invalid codemod entry. Codemods must contain a "id" string and "apply" function fields got ${Object.keys( - mod - )}` + mod, + )}`, ); } } } catch (e) { log(`Failed to load external codemods from: ${externalMod}`); log( - `Make sure you specify a package request and the resolved module has exports.codemods as iterable` + `Make sure you specify a package request and the resolved module has exports.codemods as iterable`, ); log(`${e instanceof Error ? e.stack : e}`); } diff --git a/packages/cli/src/code-mods/st-global-custom-property-to-at-property.ts b/packages/cli/src/code-mods/st-global-custom-property-to-at-property.ts index e2c8795e77..ac81ca1776 100644 --- a/packages/cli/src/code-mods/st-global-custom-property-to-at-property.ts +++ b/packages/cli/src/code-mods/st-global-custom-property-to-at-property.ts @@ -14,7 +14,7 @@ export const stGlobalCustomPropertyToAtProperty: CodeMod = ({ ast, diagnostics, postcss.atRule({ name: 'property', params: `st-global(${property.name})`, - }) + }), ); } atRule.remove(); @@ -41,7 +41,7 @@ function parseStGlobalCustomProperty(atRule: AtRule, diagnostics: Diagnostics): { node: atRule, word: atRule.params, - } + }, ); return cssVars; } diff --git a/packages/cli/src/config/process-projects.ts b/packages/cli/src/config/process-projects.ts index 6cb8249218..2b7ff82cce 100644 --- a/packages/cli/src/config/process-projects.ts +++ b/packages/cli/src/config/process-projects.ts @@ -15,7 +15,7 @@ interface ProcessProjectsOptions { export function processProjects

( { projects, presets }: MultipleProjectsConfig

, - { defaultOptions = createDefaultOptions() }: ProcessProjectsOptions = {} + { defaultOptions = createDefaultOptions() }: ProcessProjectsOptions = {}, ) { const entities: RawProjectEntity[] = []; if (!Array.isArray(projects) && typeof projects !== 'object') { @@ -28,8 +28,8 @@ export function processProjects

( resolveProjectEntry( typeof entry === 'string' ? [entry] : entry, defaultOptions, - presets - ) + presets, + ), ); } } else if (typeof projects === 'object') { @@ -46,7 +46,7 @@ export function processProjects

( function resolveProjectEntry

( [request, value]: [string, ProjectEntryValues

] | [string], configOptions: BuildOptions, - availablePresets: Presets = {} + availablePresets: Presets = {}, ): RawProjectEntity { const totalOptions: Array = []; @@ -87,8 +87,8 @@ function resolveProjectEntry

( mergeBuildOptions( configOptions, resolvePreset(presetName, availablePresets), - entryValue.options || {} - ) + entryValue.options || {}, + ), ); } else { return [entryValue]; @@ -101,7 +101,7 @@ function resolveProjectEntry

( function resolvePreset( presetName: string, - availablePresets: NonNullable['presets']> + availablePresets: NonNullable['presets']>, ): BuildOptions | PartialBuildOptions { const preset = availablePresets[presetName]; diff --git a/packages/cli/src/config/projects-config.ts b/packages/cli/src/config/projects-config.ts index 64fbf8c394..0a9d498846 100644 --- a/packages/cli/src/config/projects-config.ts +++ b/packages/cli/src/config/projects-config.ts @@ -32,12 +32,12 @@ export async function projectsConfig( rootDir: string, overrideBuildOptions: Partial, defaultOptions: BuildOptions = createDefaultOptions(), - config?: StylableRuntimeConfigs + config?: StylableRuntimeConfigs, ): Promise { const topLevelOptions = mergeBuildOptions( defaultOptions, config?.stcConfig?.options, - overrideBuildOptions + overrideBuildOptions, ); validateOptions(topLevelOptions); @@ -92,7 +92,7 @@ function resolveConfigValue(config: any, fs?: IFileSystem) { defaultConfig: typeof config.defaultConfig === 'function' ? config.defaultConfig(fs) : undefined, }), - 'Failed to evaluate Stylable config' + 'Failed to evaluate Stylable config', ); } @@ -105,7 +105,7 @@ function isSTCConfig(config: any): config is { stcConfig: Configuration | Config } function isMultipleConfigProject( - config: any + config: any, ): config is { stcConfig: MultipleProjectsConfig } { return Boolean(config?.stcConfig?.projects); } diff --git a/packages/cli/src/config/resolve-options.ts b/packages/cli/src/config/resolve-options.ts index 5908a62809..0845e362a4 100644 --- a/packages/cli/src/config/resolve-options.ts +++ b/packages/cli/src/config/resolve-options.ts @@ -254,7 +254,7 @@ export function createDefaultOptions(): BuildOptions { export function validateOptions( { outDir, srcDir, outputSources, dts, dtsSourceMap }: BuildOptions, - name?: string + name?: string, ) { const prefix = name ? `"${name}" options - ` : ''; @@ -267,7 +267,7 @@ export function validateOptions( prefix + 'Invalid configuration: When using "stcss" outDir and srcDir must be different.' + `\noutDir: ${outDir}` + - `\nsrcDir: ${srcDir}` + `\nsrcDir: ${srcDir}`, ); } } @@ -280,7 +280,7 @@ export function mergeBuildOptions( return Object.assign( {}, config, - ...rest.map((currentConfig) => (currentConfig ? removeUndefined(currentConfig) : {})) + ...rest.map((currentConfig) => (currentConfig ? removeUndefined(currentConfig) : {})), ); } @@ -289,13 +289,13 @@ export function createBuildIdentifier( projectRoot: string, index: number, hasMultipleOptions: boolean, - isMultipleProjects: boolean + isMultipleProjects: boolean, ) { return hasMultipleOptions ? `[${index}] ${projectRoot.replace(rootDir, '')}` : isMultipleProjects - ? projectRoot.replace(rootDir, '') - : projectRoot; + ? projectRoot.replace(rootDir, '') + : projectRoot; } export function hasStylableCSSOutput(options: BuildOptions): boolean { diff --git a/packages/cli/src/config/resolve-requests.ts b/packages/cli/src/config/resolve-requests.ts index fdcfae32d2..433e1fdb2c 100644 --- a/packages/cli/src/config/resolve-requests.ts +++ b/packages/cli/src/config/resolve-requests.ts @@ -26,7 +26,7 @@ export const resolveNpmRequests: ResolveRequests = (entities, { rootDir }) => { // validate duplicate requests, e.g. "packages/*" twice if (existingEntity.request === request) { throw new Error( - `Stylable CLI config can not have a duplicate project requests "${request}".` + `Stylable CLI config can not have a duplicate project requests "${request}".`, ); } } else { diff --git a/packages/cli/src/diagnostics-manager.ts b/packages/cli/src/diagnostics-manager.ts index 6ec0e535d4..4947f38499 100644 --- a/packages/cli/src/diagnostics-manager.ts +++ b/packages/cli/src/diagnostics-manager.ts @@ -33,7 +33,7 @@ export class DiagnosticsManager { public set( identifier: string, filepath?: string, - processDiagnostics?: ProcessDiagnostics + processDiagnostics?: ProcessDiagnostics, ): void { if (this.store.has(identifier) && filepath && processDiagnostics) { this.store.get(identifier)!.set(filepath, processDiagnostics); @@ -41,8 +41,8 @@ export class DiagnosticsManager { this.store.set( identifier, new Map( - filepath && processDiagnostics ? [[filepath, processDiagnostics]] : undefined - ) + filepath && processDiagnostics ? [[filepath, processDiagnostics]] : undefined, + ), ); } } @@ -103,7 +103,7 @@ export class DiagnosticsManager { const hasFatalDiagnostics = reportDiagnostics( this.log, diagnosticMessages, - diagnosticMode + diagnosticMode, ); this.options.hooks?.postReport?.(diagnosticMessages, hasFatalDiagnostics); diff --git a/packages/cli/src/directory-process-service/directory-process-service.ts b/packages/cli/src/directory-process-service/directory-process-service.ts index 82a507ad6c..09237c6373 100644 --- a/packages/cli/src/directory-process-service/directory-process-service.ts +++ b/packages/cli/src/directory-process-service/directory-process-service.ts @@ -7,7 +7,7 @@ export interface DirectoryProcessServiceOptions { watcher: DirectoryProcessService, affectedFiles: Set, deletedFiles: Set, - changeOrigin?: IWatchEvent + changeOrigin?: IWatchEvent, ): Promise<{ generatedFiles: Set }> | { generatedFiles: Set }; directoryFilter?(directoryPath: string): boolean; fileFilter?(filePath: string): boolean; @@ -22,7 +22,10 @@ export interface DirectoryProcessServiceOptions { export class DirectoryProcessService { public invalidationMap = new Map>(); public watchedDirectoryFiles = new Map>(); - constructor(private fs: IFileSystem, private options: DirectoryProcessServiceOptions = {}) { + constructor( + private fs: IFileSystem, + private options: DirectoryProcessServiceOptions = {}, + ) { if (this.options.watchMode && !this.options.watchOptions?.skipInitialWatch) { this.startWatch(); } @@ -100,7 +103,7 @@ export class DirectoryProcessService { } public async handleWatchChange( files: Map, - originalEvent: IWatchEvent + originalEvent: IWatchEvent, ): Promise<{ hasChanges: boolean; generatedFiles: Set; @@ -164,7 +167,7 @@ export class DirectoryProcessService { this, affectedFiles, deletedFiles, - originalEvent + originalEvent, ); return { diff --git a/packages/cli/src/directory-process-service/walk-fs.ts b/packages/cli/src/directory-process-service/walk-fs.ts index 36195df717..2ebffaa584 100644 --- a/packages/cli/src/directory-process-service/walk-fs.ts +++ b/packages/cli/src/directory-process-service/walk-fs.ts @@ -17,7 +17,7 @@ export async function* directoryDeepChildren( fs: IFileSystem, directoryPath: string, filterItem: (item: DirectoryItem) => boolean = returnsTrue, - basePath = directoryPath + basePath = directoryPath, ): AsyncGenerator { for (const item of await fs.promises.readdir(directoryPath, { withFileTypes: true, diff --git a/packages/cli/src/generate-manifest.ts b/packages/cli/src/generate-manifest.ts index fa72fa6866..799c90510d 100644 --- a/packages/cli/src/generate-manifest.ts +++ b/packages/cli/src/generate-manifest.ts @@ -10,7 +10,7 @@ export function generateManifest( stylable: Stylable, mode: string, log: Log, - fs: any + fs: any, ) { function getBuildNamespace(stylable: Stylable, filePath: string): string { return stylable.fileProcessor.process(filePath).namespace; @@ -23,21 +23,21 @@ export function generateManifest( (manifest, filePath) => { manifest.namespaceMapping[relative(rootDir, filePath)] = getBuildNamespace( stylable, - filePath + filePath, ); return manifest; }, { namespaceMapping: {}, - } + }, ); log(mode, 'creating manifest file: '); tryRun( () => ensureDirectory(dirname(manifestOutputPath), fs), - `Ensure directory for manifest: ${manifestOutputPath}` + `Ensure directory for manifest: ${manifestOutputPath}`, ); tryRun( () => fs.writeFileSync(manifestOutputPath, JSON.stringify(manifest)), - 'Write Index File Error' + 'Write Index File Error', ); } diff --git a/packages/cli/src/handle-assets.ts b/packages/cli/src/handle-assets.ts index baa91baa54..af262f3aa5 100644 --- a/packages/cli/src/handle-assets.ts +++ b/packages/cli/src/handle-assets.ts @@ -6,7 +6,7 @@ export function handleAssets( rootDir: string, srcDir: string, outDir: string, - fs: IFileSystem + fs: IFileSystem, ) { const generatedAssets = new Set(); diff --git a/packages/cli/src/helpers.ts b/packages/cli/src/helpers.ts index df42312c20..e558fef9e0 100644 --- a/packages/cli/src/helpers.ts +++ b/packages/cli/src/helpers.ts @@ -1,5 +1,5 @@ export function removeUndefined(obj: T) { return Object.fromEntries( - Object.entries(obj).filter(([, value]) => typeof value !== 'undefined') + Object.entries(obj).filter(([, value]) => typeof value !== 'undefined'), ) as Required>; } diff --git a/packages/cli/src/logger.ts b/packages/cli/src/logger.ts index 46660632b8..c82925a7c3 100644 --- a/packages/cli/src/logger.ts +++ b/packages/cli/src/logger.ts @@ -6,7 +6,7 @@ export const levels = { export function createLogger( onLog: (level: 'info' | 'debug', ...messages: string[]) => void, - onClear: () => void + onClear: () => void, ) { return function log(...messages: any[]) { const clear = messages[messages.length - 1] === levels.clear; @@ -30,6 +30,6 @@ export type Log = (...args: [...any[]]) => void; export function createDefaultLogger() { return createLogger( (level, ...messages) => level === 'info' && console.log(...messages), - console.clear + console.clear, ); } diff --git a/packages/cli/src/name-template.ts b/packages/cli/src/name-template.ts index 866c1a6320..80ecb60b91 100644 --- a/packages/cli/src/name-template.ts +++ b/packages/cli/src/name-template.ts @@ -1,5 +1,5 @@ export function nameTemplate(template: string, data: Record) { return template.replace(/\[(.*?)\]/gm, (origin, key) => - data[key] !== undefined ? data[key] : origin + data[key] !== undefined ? data[key] : origin, ); } diff --git a/packages/cli/src/report-diagnostics.ts b/packages/cli/src/report-diagnostics.ts index a214a913ad..7443935415 100644 --- a/packages/cli/src/report-diagnostics.ts +++ b/packages/cli/src/report-diagnostics.ts @@ -12,7 +12,7 @@ export type DiagnosticMessages = Map; export function reportDiagnostics( log: Log, diagnosticsMessages: DiagnosticMessages, - diagnosticsMode?: string + diagnosticsMode?: string, ) { let message = '[Stylable Diagnostics]'; for (const [filePath, diagnostics] of diagnosticsMessages.entries()) { @@ -30,7 +30,7 @@ export function reportDiagnostics( function hasErrorOrWarning(diagnosticsMessages: DiagnosticMessages) { for (const diagnostics of diagnosticsMessages.values()) { const has = diagnostics.some( - (diagnostic) => diagnostic.severity === 'error' || diagnostic.severity === 'warning' + (diagnostic) => diagnostic.severity === 'error' || diagnostic.severity === 'warning', ); if (has) { diff --git a/packages/cli/src/stc-builder.ts b/packages/cli/src/stc-builder.ts index d14ad27229..966a13ee64 100644 --- a/packages/cli/src/stc-builder.ts +++ b/packages/cli/src/stc-builder.ts @@ -51,7 +51,7 @@ export class STCBuilder { private fs: STCBuilderFileSystem, private configFilePath?: string, private log?: Log, - private watchMode?: boolean + private watchMode?: boolean, ) { this.diagnosticsManager = new DiagnosticsManager({ log: this.log, @@ -135,7 +135,7 @@ export class STCBuilder { public reportDiagnostics = ( context: EmitDiagnosticsContext, diagnosticsMode: DiagnosticsMode, - remove = false + remove = false, ) => { for (const [filePath] of this.diagnosticsMessages.entries()) { this.reportDiagnostic(filePath, context, diagnosticsMode, remove); @@ -152,7 +152,7 @@ export class STCBuilder { filePath: string, context: EmitDiagnosticsContext, diagnosticsMode: DiagnosticsMode, - remove = false + remove = false, ) => { const diagnostics = this.diagnosticsMessages.get(filePath); @@ -169,7 +169,7 @@ export class STCBuilder { diagnostic.line && diagnostic.column ? `:${diagnostic.line}:${diagnostic.column}` : '' - }` + }`, ); } @@ -189,7 +189,7 @@ export class STCBuilder { for (const filePath of modifiedFiles) { const event = createWatchEvent( - this.fs.existsSync(filePath) ? this.fs.realpathSync(filePath) : filePath + this.fs.existsSync(filePath) ? this.fs.realpathSync(filePath) : filePath, ); await this.watchHandler.listener(event); @@ -204,7 +204,7 @@ function createNoopLogger() { }, () => { return; - } + }, ); } diff --git a/packages/cli/src/types.ts b/packages/cli/src/types.ts index 170c4bb1a9..b583e1a82b 100644 --- a/packages/cli/src/types.ts +++ b/packages/cli/src/types.ts @@ -25,12 +25,12 @@ export type ConfigurationProvider

= () => Configurati * @deprecated use stcConfig() instead */ export function typedConfiguration

( - configOrConfigProvider: Configuration

| ConfigurationProvider

+ configOrConfigProvider: Configuration

| ConfigurationProvider

, ) { return configOrConfigProvider; } export function stcConfig

( - configOrConfigProvider: Configuration

| ConfigurationProvider

+ configOrConfigProvider: Configuration

| ConfigurationProvider

, ) { return configOrConfigProvider; } @@ -47,7 +47,7 @@ export interface RawProjectEntity { export type STCProjects = ProjectEntity[]; export type ResolveRequests = ( projects: Array, - context: ResolveProjectsContext + context: ResolveProjectsContext, ) => Promise | STCProjects; export interface ResolveProjectsContext { diff --git a/packages/cli/src/watch-handler.ts b/packages/cli/src/watch-handler.ts index d81e10399f..e1861d0b93 100644 --- a/packages/cli/src/watch-handler.ts +++ b/packages/cli/src/watch-handler.ts @@ -40,7 +40,10 @@ export class WatchHandler { private diagnosticsManager: DiagnosticsManager; private generatedFiles = new Set(); - constructor(private fileSystem: IFileSystem, private options: WatchHandlerOptions = {}) { + constructor( + private fileSystem: IFileSystem, + private options: WatchHandlerOptions = {}, + ) { this.resolverCache = this.options.resolverCache ?? new Map(); this.log = this.options.log ?? createDefaultLogger(); this.diagnosticsManager = @@ -105,7 +108,7 @@ export class WatchHandler { this.log( buildMessages.NO_DIAGNOSTICS(), buildMessages.CONTINUE_WATCH(), - levels.info + levels.info, ); } else { this.log(buildMessages.CONTINUE_WATCH(), levels.info); diff --git a/packages/cli/test/assets.spec.ts b/packages/cli/test/assets.spec.ts index ae2594da7f..d74301a848 100644 --- a/packages/cli/test/assets.spec.ts +++ b/packages/cli/test/assets.spec.ts @@ -46,7 +46,7 @@ describe('assets', function () { log() { /**/ }, - } + }, ); expect(fs.readdirSync('/dist')).to.eql([ @@ -88,7 +88,7 @@ describe('assets', function () { log() { /**/ }, - } + }, ); expect(fs.readdirSync('/dist')).to.eql([ diff --git a/packages/cli/test/build.spec.ts b/packages/cli/test/build.spec.ts index 27e572bce3..bc7346548b 100644 --- a/packages/cli/test/build.spec.ts +++ b/packages/cli/test/build.spec.ts @@ -54,7 +54,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); [ @@ -100,7 +100,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); [ @@ -113,10 +113,10 @@ describe('build stand alone', () => { }); expect(fs.readFileSync('/lib/main.st.css.js', 'utf-8')).to.include( - 'require("./global.css.js");' + 'require("./global.css.js");', ); expect(fs.readFileSync('/lib/main.st.css.mjs', 'utf-8')).to.include( - 'import "./global.css.mjs";' + 'import "./global.css.mjs";', ); }); @@ -145,7 +145,7 @@ describe('build stand alone', () => { resolveNamespace(n, s) { const normalizedWindowsRoot = fs.relative( '/', - s.replace(/^\w:\\/, '/').replace('\\', '/') + s.replace(/^\w:\\/, '/').replace('\\', '/'), ); return n + murmurhash3_32_gc(normalizedWindowsRoot); }, @@ -165,7 +165,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); [ @@ -178,7 +178,7 @@ describe('build stand alone', () => { }); expect(fs.readFileSync('/cjs/main.st.css', 'utf-8')).to.include( - 'st-namespace-reference="../src/main.st.css"' + 'st-namespace-reference="../src/main.st.css"', ); await build( @@ -193,13 +193,13 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); // check two builds using sourceNamespace are identical // compare two serializable js modules including their namespace expect(fs.readFileSync('/cjs/main.st.css.js', 'utf-8')).to.equal( - fs.readFileSync('/cjs2/main.st.css.js', 'utf-8') + fs.readFileSync('/cjs2/main.st.css.js', 'utf-8'), ); }); @@ -241,15 +241,15 @@ describe('build stand alone', () => { log, diagnosticsManager, identifier, - } + }, ); const messages = diagnosticsManager.get(identifier, '/comp.st.css')!.diagnostics; expect(messages[0].message).to.contain( - cssClassDiagnostics.CANNOT_RESOLVE_EXTEND('MissingComp') + cssClassDiagnostics.CANNOT_RESOLVE_EXTEND('MissingComp'), ); expect(messages[1].message).to.contain( - stImportDiagnostics.UNKNOWN_IMPORTED_FILE('./missing-file.st.css') + stImportDiagnostics.UNKNOWN_IMPORTED_FILE('./missing-file.st.css'), ); expect(messages[2].message).to.contain(stVarDiagnostics.UNKNOWN_VAR('missingVar')); }); @@ -287,7 +287,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const builtFile = fs.readFileSync('/dist/comp.global.css', 'utf8'); @@ -344,7 +344,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const builtFile = fs.readFileSync('/dist/comp.st.css.js', 'utf8'); @@ -385,7 +385,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const builtFile = fs.readFileSync('/dist/comp.global.css', 'utf8'); @@ -431,7 +431,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const builtFileCjs = fs.readFileSync('/dist/comp.st.css.js', 'utf8'); @@ -443,14 +443,14 @@ describe('build stand alone', () => { const runtimeMjs = fs.readFileSync('/dist/stylable-esm-runtime.mjs', 'utf8'); expect(builtFileCjs, 'imports the cjs runtime with full extension').to.contain( - `./stylable-cjs-runtime.js` + `./stylable-cjs-runtime.js`, ); expect(builtFileEsm, 'imports the esm runtime with full extension').to.contain( - `./stylable-esm-runtime.mjs` + `./stylable-esm-runtime.mjs`, ); expect( innerPathBuiltFileEsm, - 'imports the esm runtime with full extension with relative path' + 'imports the esm runtime with full extension with relative path', ).to.contain(`./../stylable-esm-runtime.mjs`); expect(runtimeCjs).to.eql(`// runtime cjs`); expect(runtimeMjs).to.eql(`// runtime esm`); @@ -488,17 +488,17 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const builtFileCjs = fs.readFileSync('/dist/comp.st.css.cjs', 'utf8'); const builtFileEsm = fs.readFileSync('/dist/comp.st.css.js', 'utf8'); expect(builtFileCjs, 'imports the cjs runtime with full extension').to.contain( - `"@stylable/runtime"` + `"@stylable/runtime"`, ); expect(builtFileEsm, 'imports the esm runtime with full extension').to.contain( - `"@stylable/runtime"` + `"@stylable/runtime"`, ); }); @@ -533,14 +533,14 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); expect(fs.readFileSync('/dist/comp.st.css.js', 'utf8')).contains( - `require("./comp.global.css")` + `require("./comp.global.css")`, ); expect(fs.readFileSync('/dist/comp.st.css.mjs', 'utf8')).contains( - `import "./comp.global.css"` + `import "./comp.global.css"`, ); expect(fs.existsSync('/dist/comp.global.css')).to.equal(true); }); @@ -571,7 +571,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); ['/main.st.css', '/main.st.css.d.ts'].forEach((p) => { @@ -613,7 +613,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); ['/main.st.css', '/main.st.css.d.ts'].forEach((p) => { @@ -669,7 +669,7 @@ describe('build stand alone', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); ['/main.st.css', '/main.st.css.d.ts', '/main.st.css.d.ts.map'].forEach((p) => { @@ -726,11 +726,11 @@ describe('build - bundle', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); expect(fs.readFileSync('/lib/bundle.css', 'utf8')).to.equal( - '.comp__baga{color:red}.main__gaga{color:#00f}' + '.comp__baga{color:red}.main__gaga{color:#00f}', ); }); it('should rewrite relative urls', async () => { @@ -774,11 +774,11 @@ describe('build - bundle', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); expect(fs.readFileSync('/lib/bundle.css', 'utf8')).to.equal( - '.label__part,.button__root{background-image:url(./components/label/image.png)}' + '.label__part,.button__root{background-image:url(./components/label/image.png)}', ); }); }); diff --git a/packages/cli/test/cli-codemod.spec.ts b/packages/cli/test/cli-codemod.spec.ts index ce4441341d..c39ab1c60b 100644 --- a/packages/cli/test/cli-codemod.spec.ts +++ b/packages/cli/test/cli-codemod.spec.ts @@ -88,7 +88,7 @@ describe('Stylable Cli Code Mods', () => { expect(dirContent['style.st.css']).equal(`.root{}`); expect(stdout, 'Summery contains the skipped file prefixed with "−"').to.match( - /Summery:\n\[CodeMod\] − .*?style\.st\.css/ + /Summery:\n\[CodeMod\] − .*?style\.st\.css/, ); }); diff --git a/packages/cli/test/cli.spec.ts b/packages/cli/test/cli.spec.ts index 6624b1af2e..b3d61816c4 100644 --- a/packages/cli/test/cli.spec.ts +++ b/packages/cli/test/cli.spec.ts @@ -39,8 +39,8 @@ describe('Stylable Cli', function () { expect( evalStylableModule<{ namespace: string }>( dirContent['style.st.css.js'], - 'style.st.css.js' - ).namespace + 'style.st.css.js', + ).namespace, ).equal('test-ns-0'); }); @@ -62,8 +62,8 @@ describe('Stylable Cli', function () { expect( evalStylableModule<{ namespace: string }>( dirContent['style.st.css.js'], - 'style.st.css.js' - ).namespace + 'style.st.css.js', + ).namespace, ).equal('test-ns-0'); }); @@ -151,9 +151,9 @@ describe('Stylable Cli', function () { expect( evalStylableModule<{ namespace: string }>( loadDirSync(tempDir.path)['style.st.css.js'], - 'style.st.css.js' + 'style.st.css.js', ).namespace, - 'default' + 'default', ).equal(resolveNamespace('style', join(tempDir.path, 'style.st.css'))); } { @@ -169,7 +169,7 @@ describe('Stylable Cli', function () { }; }, }; - ` + `, ); runCliSync(['--rootDir', tempDir.path, '--cjs']); @@ -177,9 +177,9 @@ describe('Stylable Cli', function () { expect( evalStylableModule<{ namespace: string }>( loadDirSync(tempDir.path)['style.st.css.js'], - 'style.st.css.js' + 'style.st.css.js', ).namespace, - 'stylable.config' + 'stylable.config', ).equal('config-ns-0'); } { @@ -191,7 +191,7 @@ describe('Stylable Cli', function () { module.exports.resolveNamespace = function resolveNamespace() { return 'custom-ns-' + c++; } - ` + `, ); runCliSync(['--rootDir', tempDir.path, '--nsr', './custom-ns-resolver.js', '--cjs']); @@ -199,9 +199,9 @@ describe('Stylable Cli', function () { expect( evalStylableModule<{ namespace: string }>( loadDirSync(tempDir.path)['style.st.css.js'], - 'style.st.css.js' + 'style.st.css.js', ).namespace, - 'cli argument' + 'cli argument', ).equal('custom-ns-0'); } }); @@ -225,7 +225,7 @@ describe('Stylable Cli', function () { const stylesheetContent = dirContent['dist/style.st.css']; expect(stylesheetContent.endsWith('/* st-namespace-reference="../style.st.css" */')).equal( - true + true, ); }); @@ -254,10 +254,10 @@ describe('Stylable Cli', function () { expect(stylesheetContent).to.equal(srcContent); expect(dtsContent.startsWith('/* THIS FILE IS AUTO GENERATED DO NOT MODIFY */')).to.equal( - true + true, ); expect( - dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"') + dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"'), ).to.equal(true); }); @@ -281,10 +281,10 @@ describe('Stylable Cli', function () { const dtsSourceMapContent = dirContent['dist/style.st.css.d.ts.map']; expect(dtsContent.startsWith('/* THIS FILE IS AUTO GENERATED DO NOT MODIFY */')).to.equal( - true + true, ); expect( - dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"') + dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"'), ).to.equal(true); expect(status).to.equal(0); @@ -304,11 +304,11 @@ describe('Stylable Cli', function () { const dtsSourceMapContent = dirContent['dist/style.st.css.d.ts.map']; expect( - dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"') + dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"'), ).to.equal(true); expect(dtsSourceMapContent).to.contain( `"sources": [\n "../src/style.st.css"\n ]`, - `expected to contain source file path for "${dtsSourceMapContent}"` + `expected to contain source file path for "${dtsSourceMapContent}"`, ); }); @@ -336,7 +336,7 @@ describe('Stylable Cli', function () { const dtsSourceMapContent = dirContent['dist/style.st.css.d.ts.map']; expect( - dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"') + dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"'), ).to.equal(true); expect(dtsSourceMapContent).to.contain(`"sources": [\n "style.st.css"\n ]`); }); @@ -366,10 +366,10 @@ describe('Stylable Cli', function () { expect(stylesheetContent).to.equal(srcContent); expect(dtsContent.startsWith('/* THIS FILE IS AUTO GENERATED DO NOT MODIFY */')).to.equal( - true + true, ); expect( - dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"') + dtsSourceMapContent.startsWith('{\n "version": 3,\n "file": "style.st.css.d.ts"'), ).to.equal(true); }); @@ -400,7 +400,7 @@ describe('Stylable Cli', function () { expect(stylesheetContent).to.equal(srcContent); expect(dtsContent.startsWith('/* THIS FILE IS AUTO GENERATED DO NOT MODIFY */')).to.equal( - true + true, ); expect(dtsSourceMapContent).to.equal(undefined); }); @@ -492,8 +492,8 @@ describe('Stylable Cli', function () { expect(status).to.equal(0); expect(stdout, 'stdout').to.match( new RegExp( - `No target output declared for "(.*?)", please provide one or more of the following target options: "cjs", "esm", "css", "stcss" or "indexFile"` - ) + `No target output declared for "(.*?)", please provide one or more of the following target options: "cjs", "esm", "css", "stcss" or "indexFile"`, + ), ); }); @@ -516,9 +516,9 @@ describe('Stylable Cli', function () { new RegExp( `\\[info\\: \\d+]: ${stVarDiagnostics.DEPRECATED_ST_FUNCTION_NAME( 'stArray', - 'st-array' - )}` - ) + 'st-array', + )}`, + ), ); }); @@ -581,8 +581,8 @@ describe('Stylable Cli', function () { expect(status).to.equal(1); expect( stdout.match( - new RegExp(STImport.diagnostics.NO_ST_IMPORT_IN_NESTED_SCOPE().message, 'g') - ) + new RegExp(STImport.diagnostics.NO_ST_IMPORT_IN_NESTED_SCOPE().message, 'g'), + ), ).to.have.length(1); }); @@ -603,7 +603,7 @@ describe('Stylable Cli', function () { '--cjs=false', ]); expect(res.stderr).to.contain( - 'Error: Invalid configuration: When using "stcss" outDir and srcDir must be different.' + 'Error: Invalid configuration: When using "stcss" outDir and srcDir must be different.', ); }); }); @@ -675,7 +675,7 @@ describe('Stylable Cli', function () { return { resolveModule: createWebpackResolver(fs, { plugins: [new TsconfigPathsPlugin({ configFile: join(${JSON.stringify( - tempDir.path + tempDir.path, )},'tsconfig.json') })], }) }; diff --git a/packages/cli/test/code-format-cli.spec.ts b/packages/cli/test/code-format-cli.spec.ts index 2245100544..b63d22a5d8 100644 --- a/packages/cli/test/code-format-cli.spec.ts +++ b/packages/cli/test/code-format-cli.spec.ts @@ -154,7 +154,7 @@ describe('Stylable Code Format Cli', function () { green, blue; } - `) + `), ); }); it('should accept configuration', () => { @@ -186,7 +186,7 @@ describe('Stylable Code Format Cli', function () { prop2: 123456789 123456789; } - `) + '\n' + `) + '\n', ); // }); @@ -207,7 +207,7 @@ describe('Stylable Code Format Cli', function () { expect(dirContent[filePath]).to.equal(fileContent); expect(stdout).to.equal(''); expect(stderr).to.include( - 'cannot find any Stylable stylesheets (.st.css) in directory' + 'cannot find any Stylable stylesheets (.st.css) in directory', ); }); diff --git a/packages/cli/test/codemods/namespace-to-st-namespace.spec.ts b/packages/cli/test/codemods/namespace-to-st-namespace.spec.ts index cf0058454c..ad1e170388 100644 --- a/packages/cli/test/codemods/namespace-to-st-namespace.spec.ts +++ b/packages/cli/test/codemods/namespace-to-st-namespace.spec.ts @@ -52,7 +52,7 @@ describe('CLI Codemods namespace-to-st-namespace', () => { const dirContent = loadDirSync(tempDir.path); expect(dirContent['style.st.css']).equal( - '@namespace "http://button"; @namespace prefix "btn";' + '@namespace "http://button"; @namespace prefix "btn";', ); }); }); diff --git a/packages/cli/test/codemods/st-global-custom-property-to-at-property.spec.ts b/packages/cli/test/codemods/st-global-custom-property-to-at-property.spec.ts index 823bb0265d..e9bc13c678 100644 --- a/packages/cli/test/codemods/st-global-custom-property-to-at-property.spec.ts +++ b/packages/cli/test/codemods/st-global-custom-property-to-at-property.spec.ts @@ -55,7 +55,7 @@ describe('CLI Codemods st-global-custom-property-to-at-property', () => { const dirContent = loadDirSync(tempDir.path); expect(dirContent['style.st.css']).equal( - '@property st-global(--myVar);\n@property st-global(--mySecondVar);\n@property st-global(--myThirdVar);' + '@property st-global(--myVar);\n@property st-global(--mySecondVar);\n@property st-global(--myThirdVar);', ); }); @@ -77,12 +77,12 @@ describe('CLI Codemods st-global-custom-property-to-at-property', () => { expect(stdout).to.match( new RegExp( `style.st.css: ${cssCustomPropertyDiagnostics.GLOBAL_CSS_VAR_MISSING_COMMA( - '--myVar --mySecondVar' - )}` - ) + '--myVar --mySecondVar', + )}`, + ), ); expect(dirContent['style.st.css']).equal( - '@st-global-custom-property --myVar --mySecondVar;' + '@st-global-custom-property --myVar --mySecondVar;', ); }); }); diff --git a/packages/cli/test/codemods/st-import-to-at-import.spec.ts b/packages/cli/test/codemods/st-import-to-at-import.spec.ts index 9cac8f4f9e..fcb4890c69 100644 --- a/packages/cli/test/codemods/st-import-to-at-import.spec.ts +++ b/packages/cli/test/codemods/st-import-to-at-import.spec.ts @@ -29,7 +29,7 @@ describe('CLI Codemods st-import-to-at-import', () => { const dirContent = loadDirSync(tempDir.path); expect(dirContent['style.st.css']).equal( - '@st-import Name, [name1 as name1Alias, name2, --var1, keyframes(kf1 as kf1Alias, kf2, kf3, kf4)] from "./x";' + '@st-import Name, [name1 as name1Alias, name2, --var1, keyframes(kf1 as kf1Alias, kf2, kf3, kf4)] from "./x";', ); }); @@ -49,7 +49,7 @@ describe('CLI Codemods st-import-to-at-import', () => { const dirContent = loadDirSync(tempDir.path); expect(dirContent['style.st.css']).equal( - `:import {-st-from: './x.st.css'; -st-from: './y.st.css';}` + `:import {-st-from: './x.st.css'; -st-from: './y.st.css';}`, ); expect(stdout).to.match(new RegExp(parseImportMessages.MULTIPLE_FROM_IN_IMPORT().message)); }); diff --git a/packages/cli/test/config-options.spec.ts b/packages/cli/test/config-options.spec.ts index 023bdac964..4900f84dfc 100644 --- a/packages/cli/test/config-options.spec.ts +++ b/packages/cli/test/config-options.spec.ts @@ -212,7 +212,7 @@ describe('Stylable CLI config file options', function () { options: { indexFile: 'my-index.st.css', IndexGenerator: require(${JSON.stringify( - require.resolve('./fixtures/test-generator') + require.resolve('./fixtures/test-generator'), )}).Generator, outDir: './dist', } @@ -231,7 +231,7 @@ describe('Stylable CLI config file options', function () { expect(stdout, 'has diagnostic error').not.to.match(/error/i); const indexFileResult = readFileSync( - join(tempDir.path, 'dist', 'my-index.st.css') + join(tempDir.path, 'dist', 'my-index.st.css'), ).toString(); expect(indexFileResult.trim()).to.eql( @@ -240,7 +240,7 @@ describe('Stylable CLI config file options', function () { '.root Style0{}', ':import {-st-from: "../comp-A.st.css";-st-default:Style1;}', '.root Style1{}', - ].join('\n') + ].join('\n'), ); }); @@ -255,7 +255,7 @@ describe('Stylable CLI config file options', function () { options: { indexFile: 'my-index.st.css', IndexGenerator: require(${JSON.stringify( - require.resolve('./fixtures/named-exports-generator') + require.resolve('./fixtures/named-exports-generator'), )}).Generator, outDir: './dist', } @@ -279,7 +279,7 @@ describe('Stylable CLI config file options', function () { expect(stdout, 'has diagnostic error').not.to.match(/error/i); const indexFileResult = readFileSync( - join(tempDir.path, 'dist', 'my-index.st.css') + join(tempDir.path, 'dist', 'my-index.st.css'), ).toString(); expect(indexFileResult.trim()).to.eql( @@ -288,7 +288,7 @@ describe('Stylable CLI config file options', function () { '.root Style0{}', ':import {-st-from: "../comp-A.st.css";-st-default:Style1;}', '.root Style1{}', - ].join('\n') + ].join('\n'), ); }); diff --git a/packages/cli/test/config-projects.spec.ts b/packages/cli/test/config-projects.spec.ts index 359df288ff..5eb25e4cd1 100644 --- a/packages/cli/test/config-projects.spec.ts +++ b/packages/cli/test/config-projects.spec.ts @@ -482,7 +482,7 @@ describe('Stylable CLI config multiple projects', function () { .to.be.lessThan(stylableError) .and.lessThan(secondError); expect(stdout.match(STVar.diagnostics.UNKNOWN_VAR('unknown').message)?.length).to.eql( - 1 + 1, ); }); @@ -551,7 +551,7 @@ describe('Stylable CLI config multiple projects', function () { expect(stdout, 'has diagnostic error').not.to.match(/error/i); expect(stderr).to.match( - new RegExp(`Error: Stylable CLI config can not have a duplicate project requests`) + new RegExp(`Error: Stylable CLI config can not have a duplicate project requests`), ); }); @@ -586,8 +586,8 @@ describe('Stylable CLI config multiple projects', function () { expect(stdout, 'has diagnostic error').not.to.match(/error/i); expect(stderr).to.match( new RegExp( - `Error: Stylable CLI config can not resolve project request "packages/project-b"` - ) + `Error: Stylable CLI config can not resolve project request "packages/project-b"`, + ), ); }); @@ -700,7 +700,7 @@ describe('Stylable CLI config multiple projects', function () { expect(stdout, 'has diagnostic error').not.to.match(/error/i); expect(stderr, 'has cli error').to.include( - 'Error: "packages/*" options - "dtsSourceMap" requires turning on "dts"' + 'Error: "packages/*" options - "dtsSourceMap" requires turning on "dts"', ); }); }); diff --git a/packages/cli/test/directory-process-service/directory-process-service.spec.ts b/packages/cli/test/directory-process-service/directory-process-service.spec.ts index 93a4e3588e..413b879fa1 100644 --- a/packages/cli/test/directory-process-service/directory-process-service.spec.ts +++ b/packages/cli/test/directory-process-service/directory-process-service.spec.ts @@ -68,7 +68,7 @@ describe('DirectoryWatchService', () => { ` const ATemplate = use('./a.template.js'); output(\`0(\${ATemplate})\`); - ` + `, ); await waitFor(() => { @@ -82,7 +82,7 @@ describe('DirectoryWatchService', () => { '/a.template.js', ` output('A()'); - ` + `, ); await waitFor(() => { @@ -334,7 +334,7 @@ describe('DirectoryWatchService', () => { /* changed */ const CTemplate = use('./c.template.js'); output(\`B(\${CTemplate})\`); - ` + `, ); await waitFor(() => { @@ -355,7 +355,7 @@ describe('DirectoryWatchService', () => { /* changed */ const ATemplate = use('./a.template.js'); output(\`0(\${ATemplate}\`); - ` + `, ); await waitFor(() => { @@ -421,7 +421,7 @@ function writeTemplateOutputToDist(fs: IFileSystem, filePath: string, value: str function expectInvalidationMap( watcher: DirectoryProcessService, - expected: Record + expected: Record, ) { const actual: Record = {}; for (const [key, invalidationSet] of watcher.invalidationMap) { diff --git a/packages/cli/test/generate-index.spec.ts b/packages/cli/test/generate-index.spec.ts index ae914b35d7..2fcb78dabe 100644 --- a/packages/cli/test/generate-index.spec.ts +++ b/packages/cli/test/generate-index.spec.ts @@ -37,7 +37,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/index.st.css', 'utf8'); @@ -48,7 +48,7 @@ describe('build index', () => { '.root CompA{}', ':import {-st-from: "./a/b/comp-B.st.css";-st-default:CompB;}', '.root CompB{}', - ].join('\n') + ].join('\n'), ); }); it('should create index file importing all matched stylesheets in outDir (outputSources)', async () => { @@ -82,7 +82,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('./dist/index.st.css', 'utf8'); @@ -93,7 +93,7 @@ describe('build index', () => { '.root CompA{}', ':import {-st-from: "./a/b/comp-B.st.css";-st-default:CompB;}', '.root CompB{}', - ].join('\n') + ].join('\n'), ); }); @@ -128,7 +128,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/dist/index.st.css', 'utf8'); @@ -139,7 +139,7 @@ describe('build index', () => { '.root CompA{}', ':import {-st-from: "../src/a/b/comp-B.st.css";-st-default:CompB;}', '.root CompB{}', - ].join('\n') + ].join('\n'), ); }); it('should create index file using a the default generator', async () => { @@ -170,7 +170,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/index.st.css', 'utf8'); @@ -181,7 +181,7 @@ describe('build index', () => { '.root CompA{}', ':import {-st-from: "./b/1-some-comp-B-.st.css";-st-default:SomeCompB;}', '.root SomeCompB{}', - ].join('\n') + ].join('\n'), ); }); it('should create index file using a custom generator', async () => { @@ -213,7 +213,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/index.st.css', 'utf8'); @@ -224,7 +224,7 @@ describe('build index', () => { '.root Style0{}', ':import {-st-from: "./b/1-some-comp-B-.st.css";-st-default:Style1;}', '.root Style1{}', - ].join('\n') + ].join('\n'), ); }); it('should create index file when srcDir is parent directory of outDir', async () => { @@ -257,7 +257,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); expect(fs.existsSync('/index.st.css'), 'index is not generated').to.eql(true); @@ -270,7 +270,7 @@ describe('build index', () => { '.root CompA{}', ':import {-st-from: "./dist/a/b/comp-B.st.css";-st-default:CompB;}', '.root CompB{}', - ].join('\n') + ].join('\n'), ); }); it('custom generator is able to filter files from the index', async () => { @@ -302,13 +302,13 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/index.st.css', 'utf8'); expect(res.trim()).to.equal( - ':import {-st-from: "./comp-A.st.css";-st-default:Style0;}\n.root Style0{}' + ':import {-st-from: "./comp-A.st.css";-st-default:Style0;}\n.root Style0{}', ); }); it('should create index file using a custom generator with named exports generation and @st-namespace', async () => { @@ -346,7 +346,7 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/index.st.css', 'utf8'); @@ -360,7 +360,7 @@ describe('build index', () => { ':import {-st-from: "./b/1-some-comp-B-.st.css";-st-default:SomeCompB;-st-named: b as SomeCompB__b;}', '.root SomeCompB{}', '.root .SomeCompB__b{}', - ].join('\n') + ].join('\n'), ); }); it('should create non-existing folders in path to the generated indexFile', async () => { @@ -387,13 +387,15 @@ describe('build index', () => { rootDir: '/', projectRoot: '/', log, - } + }, ); const res = fs.readFileSync('/some-dir/other-dir/index.st.css', 'utf8'); expect(res.trim()).to.equal( - [':import {-st-from: "../../comp.st.css";-st-default:Comp;}', '.root Comp{}'].join('\n') + [':import {-st-from: "../../comp.st.css";-st-default:Comp;}', '.root Comp{}'].join( + '\n', + ), ); }); it('should handle name collisions by failing', async () => { @@ -427,11 +429,11 @@ describe('build index', () => { projectRoot: '/', log, diagnosticsManager, - } + }, ); expect(diagnosticsManager.get('/', '/a/comp.st.css')?.diagnostics[0].message).to.equal( - `Name Collision Error:\nexport symbol Comp from ${'/a/comp.st.css'} is already used by ${'/comp.st.css'}` + `Name Collision Error:\nexport symbol Comp from ${'/a/comp.st.css'} is already used by ${'/comp.st.css'}`, ); }); }); diff --git a/packages/cli/test/watch-multiple-projects.spec.ts b/packages/cli/test/watch-multiple-projects.spec.ts index 21a026f253..54066672dd 100644 --- a/packages/cli/test/watch-multiple-projects.spec.ts +++ b/packages/cli/test/watch-multiple-projects.spec.ts @@ -62,14 +62,14 @@ describe('Stylable Cli Watch - Multiple projects', function () { action() { return writeToExistingFile( join(tempDir.path, 'packages', 'project-a', 'style.st.css'), - '.root{ color:yellow; }' + '.root{ color:yellow; }', ); }, }, { msg: buildMessages.FINISHED_PROCESSING( 1, - join(tempDir.path, 'packages', 'project-a') + join(tempDir.path, 'packages', 'project-a'), ), }, ], @@ -135,7 +135,7 @@ describe('Stylable Cli Watch - Multiple projects', function () { join(tempDir.path, './packages/project-b/src/depend.st.css'), `:vars { color: blue; - }` + }`, ); }, }, @@ -152,15 +152,15 @@ describe('Stylable Cli Watch - Multiple projects', function () { expect(files['packages/project-a/dist/style.css']).to.include('color:blue'); expect( Object.keys(files).some( - (fileName) => fileName.includes('project-b') && fileName.includes('style.st.css') + (fileName) => fileName.includes('project-b') && fileName.includes('style.st.css'), ), - 'have files from package "a" inside package "b"' + 'have files from package "a" inside package "b"', ).to.eql(false); expect( Object.keys(files).some( - (fileName) => fileName.includes('project-a') && fileName.includes('depend.st.css') + (fileName) => fileName.includes('project-a') && fileName.includes('depend.st.css'), ), - 'have files from package "b" inside package "a"' + 'have files from package "b" inside package "a"', ).to.eql(false); }); @@ -236,13 +236,13 @@ describe('Stylable Cli Watch - Multiple projects', function () { .a::foo {color: red;} .a::bar {color: blue;} - ` + `, ); }, }, { msg: buildMessages.CHANGE_DETECTED( - join(tempDir.path, 'packages', 'project-a', 'style.st.css') + join(tempDir.path, 'packages', 'project-a', 'style.st.css'), ), action() { return writeToExistingFile( @@ -250,18 +250,18 @@ describe('Stylable Cli Watch - Multiple projects', function () { ` .foo {} .bar {} - ` + `, ); }, }, { msg: buildMessages.CHANGE_DETECTED( - join(tempDir.path, 'packages', 'project-b', 'foo.st.css') + join(tempDir.path, 'packages', 'project-b', 'foo.st.css'), ), }, { msg: buildMessages.CHANGE_EVENT_TRIGGERED( - join(tempDir.path, 'packages', 'project-b', 'dist', 'index.st.css') + join(tempDir.path, 'packages', 'project-b', 'dist', 'index.st.css'), ), }, ], @@ -270,11 +270,11 @@ describe('Stylable Cli Watch - Multiple projects', function () { const files = loadDirSync(tempDir.path); expect( files['packages/project-a/dist/style.css'], - `Expected styling to apply.\nBuild output:\n\n${output()}` + `Expected styling to apply.\nBuild output:\n\n${output()}`, ).to.match(/foo[0-9]+__foo {color: red;}/g); expect( files['packages/project-a/dist/style.css'], - `Expected styling to apply.\nBuild output:\n\n${output()}` + `Expected styling to apply.\nBuild output:\n\n${output()}`, ).to.match(/foo[0-9]+__bar {color: blue;}/g); }); @@ -335,7 +335,7 @@ describe('Stylable Cli Watch - Multiple projects', function () { join(tempDir.path, './packages/project-b/mixin.js'), `module.exports = { color: 'blue' - }` + }`, ); }, }, @@ -379,14 +379,14 @@ describe('Stylable Cli Watch - Multiple projects', function () { action() { return writeToExistingFile( join(tempDir.path, 'packages', 'project-a', 'style.st.css'), - '.x.y{ -st-states: z; }' + '.x.y{ -st-states: z; }', ); }, }, { msg: buildMessages.FINISHED_PROCESSING( 1, - join(tempDir.path, 'packages', 'project-a') + join(tempDir.path, 'packages', 'project-a'), ), }, { @@ -394,14 +394,14 @@ describe('Stylable Cli Watch - Multiple projects', function () { action() { return writeToExistingFile( join(tempDir.path, 'packages', 'project-a', 'style.st.css'), - '.root{ color:blue; }' + '.root{ color:blue; }', ); }, }, { msg: buildMessages.FINISHED_PROCESSING( 1, - join(tempDir.path, 'packages', 'project-a') + join(tempDir.path, 'packages', 'project-a'), ), }, ], @@ -461,14 +461,14 @@ describe('Stylable Cli Watch - Multiple projects', function () { @st-import Module from './does-not-exist.st.css'; .root{ -st-extends: Module; color:blue; } - ` + `, ); }, }, { msg: buildMessages.FINISHED_PROCESSING( 1, - `[1] ${sep + join('packages', 'project-a')}` + `[1] ${sep + join('packages', 'project-a')}`, ), }, { @@ -537,8 +537,8 @@ describe('Stylable Cli Watch - Multiple projects', function () { expect( output().match( - STImport.diagnostics.UNKNOWN_IMPORTED_FILE('./does-not-exist.st.css').message - ) + STImport.diagnostics.UNKNOWN_IMPORTED_FILE('./does-not-exist.st.css').message, + ), ).to.lengthOf(1); }); }); diff --git a/packages/cli/test/watch-single-project.spec.ts b/packages/cli/test/watch-single-project.spec.ts index 90be393149..03e1791110 100644 --- a/packages/cli/test/watch-single-project.spec.ts +++ b/packages/cli/test/watch-single-project.spec.ts @@ -54,7 +54,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeToExistingFile( join(tempDir.path, 'depend.st.css'), - '.root{ color:yellow; }' + '.root{ color:yellow; }', ); }, }, @@ -95,7 +95,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeToExistingFile( join(tempDir.path, 'deep.st.css'), - ':vars { color: green; }' + ':vars { color: green; }', ); }, }, @@ -122,7 +122,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeFile( join(tempDir.path, 'style.st.css'), - `.root{ color:green }` + `.root{ color:green }`, ); }, }, @@ -266,7 +266,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { renameSync( join(tempDir.path, 'style.st.css'), - join(tempDir.path, 'style-renamed.st.css') + join(tempDir.path, 'style-renamed.st.css'), ); }, }, @@ -349,7 +349,7 @@ describe('Stylable Cli Watch - Single project', function () { @st-import Module from './does-not-exist.st.css'; .root{ color: blue; } - ` + `, ); }, }, @@ -378,7 +378,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeFile( join(tempDir.path, 'style.st.css'), - `.root{ color:green }` + `.root{ color:green }`, ); }, }, @@ -387,7 +387,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeToExistingFile( join(tempDir.path, 'style.st.css'), - `.root{ color:blue }` + `.root{ color:blue }`, ); }, }, @@ -428,7 +428,7 @@ describe('Stylable Cli Watch - Single project', function () { expect(files['dist/bundle.css']).to.include('z-index:1'); return writeFile( join(tempDir.path, 'src', 'comp.st.css'), - `.root{ z-index:2 }` + `.root{ z-index:2 }`, ); }, }, @@ -440,7 +440,7 @@ describe('Stylable Cli Watch - Single project', function () { expect(files['dist/bundle.css']).to.include('z-index:1'); return writeFile( join(tempDir.path, 'src', 'style.st.css'), - `.root{ z-index:3 }` + `.root{ z-index:3 }`, ); }, }, @@ -512,20 +512,20 @@ describe('Stylable Cli Watch - Single project', function () { `.root{ color:red; background: url('./icon.svg') - }` + }`, ); }, }, { msg: buildMessages.FINISHED_PROCESSING( 2, - `[0] ${sep}` + join('packages', 'project-a') + `[0] ${sep}` + join('packages', 'project-a'), ), }, { msg: buildMessages.FINISHED_PROCESSING( 2, - `[1] ${sep}` + join('packages', 'project-a') + `[1] ${sep}` + join('packages', 'project-a'), ), action() { return { @@ -541,13 +541,13 @@ describe('Stylable Cli Watch - Single project', function () { new RegExp( escapeRegExp( buildMessages.CHANGE_EVENT_TRIGGERED( - join(tempDir.path, 'packages', 'project-a', 'src', 'icon.svg') - ) + join(tempDir.path, 'packages', 'project-a', 'src', 'icon.svg'), + ), ), - 'ig' - ) + 'ig', + ), )?.length, - 'svg file should trigger change event once' + 'svg file should trigger change event once', ).to.eql(2, output()); }); @@ -572,7 +572,7 @@ describe('Stylable Cli Watch - Single project', function () { action() { return writeToExistingFile( join(tempDir.path, 'style.st.css'), - `.root{ color:green }` + `.root{ color:green }`, ); }, }, diff --git a/packages/code-formatter/src/format-css.ts b/packages/code-formatter/src/format-css.ts index f58da2bafb..f581657620 100644 --- a/packages/code-formatter/src/format-css.ts +++ b/packages/code-formatter/src/format-css.ts @@ -16,7 +16,7 @@ function walkValue( ast: BaseAstNode | BaseAstNode[], visit: (node: BaseAstNode, parents: BaseAstNode[], siblings: BaseAstNode[]) => void, options: { insideOut?: boolean } = {}, - parents: BaseAstNode[] = [] + parents: BaseAstNode[] = [], ) { ast = Array.isArray(ast) ? ast : [ast]; const insideOut = !!options.insideOut; @@ -154,7 +154,7 @@ function formatAst(ast: AnyNode, index: number, options: FormatOptions) { walkValue( valueAst, normalizeDeclValueAndCollectLength(preserveComponentNewLines, NL, nodesInfo), - { insideOut: true } + { insideOut: true }, ); // format each top level segment flowDeclValueSegment({ @@ -285,7 +285,7 @@ class AtRuleParamFormatter { private getContext( node: ValueParser.BaseAstNode, parents: NodeContext['parents'], - siblings: NodeContext['parents'] + siblings: NodeContext['parents'], ): NodeContext { const index = siblings.indexOf(node); const prevNode = siblings[index - 1]; @@ -308,7 +308,7 @@ class AtRuleParamFormatter { private formatAroundComma( _node: ValueParser.Literal, context: NodeContext, - options: FormatOptions + options: FormatOptions, ) { const { prevNode, nextNode } = context; // argument delimiter @@ -323,13 +323,13 @@ class AtRuleParamFormatter { inlineSpace: ' ', }, context, - options + options, ); } private formatBlockOpen( node: ValueParser.Literal, { nextNode }: NodeContext, - { endOfLine: NL }: FormatOptions + { endOfLine: NL }: FormatOptions, ) { const isSpaceAfter = nextNode?.type === 'space'; const isNewline = isSpaceAfter && stringifyCSSValue(nextNode).includes('\n'); @@ -344,7 +344,7 @@ class AtRuleParamFormatter { private formatBlockClose( node: ValueParser.Literal, context: NodeContext, - options: FormatOptions + options: FormatOptions, ) { const { prevNode, currentBlock } = context; if (currentBlock.type === node.value) { @@ -352,7 +352,7 @@ class AtRuleParamFormatter { if (currentBlock.isNewline) { this.currentNewlineIndent = this.currentNewlineIndent.slice( 0, - this.currentNewlineIndent.length - options.indent.length + this.currentNewlineIndent.length - options.indent.length, ); } } @@ -363,7 +363,7 @@ class AtRuleParamFormatter { inlineSpace: '', }, context, - options + options, ); } private formatFunction(node: ValueParser.Call, { endOfLine: NL }: FormatOptions) { @@ -391,7 +391,7 @@ class AtRuleParamFormatter { inlineSpace: string; }, { currentBlock, siblings, index }: NodeContext, - { endOfLine: NL }: FormatOptions + { endOfLine: NL }: FormatOptions, ) { const spaceValue = currentBlock?.isNewline ? NL + this.currentNewlineIndent : inlineSpace; if (spaceNode?.type === 'space') { @@ -418,7 +418,7 @@ class AtRuleParamFormatter { if (currentBlock.isNewline) { this.currentNewlineIndent = this.currentNewlineIndent.slice( 0, - this.currentNewlineIndent.length - this.options.indent.length + this.currentNewlineIndent.length - this.options.indent.length, ); } currentBlock = this.blockCloserStack[this.blockCloserStack.length - 1]; @@ -430,11 +430,11 @@ class AtRuleParamFormatter { function normalizeDeclValueAndCollectLength( preserveTopLevelNewLines: boolean, NL: string, - nodesInfo: Map + nodesInfo: Map, ): ( node: ValueParser.BaseAstNode, parents: ValueParser.BaseAstNode[], - siblings: ValueParser.BaseAstNode[] + siblings: ValueParser.BaseAstNode[], ) => void { return (node, parents, siblings) => { const preserveNewLines = !parents.length @@ -581,7 +581,7 @@ function flowDeclValueSegment({ } function isFunctionBreakable( funcNode: Call, - nodesInfo: Map + nodesInfo: Map, ) { const totalSize = nodesInfo.get(funcNode)!.length; if (totalSize <= 30) { @@ -714,7 +714,7 @@ function parseDeclBetweenRaws(between: string) { function formatSelectors( rule: Rule, forceNL: boolean, - { endOfLine: NL, indent, indentLevel }: FormatOptions + { endOfLine: NL, indent, indentLevel }: FormatOptions, ) { const selectors = rule.selectors; const newlines = rule.selector.match(/\n/gm)?.length ?? 0; diff --git a/packages/code-formatter/src/formatter.ts b/packages/code-formatter/src/formatter.ts index 52c83371e8..28f4c39660 100644 --- a/packages/code-formatter/src/formatter.ts +++ b/packages/code-formatter/src/formatter.ts @@ -21,7 +21,7 @@ export function formatDocumentExperimental(source: string, options: Partial

{ atRule.params = atRuleChanges.shift()!; diff --git a/packages/code-formatter/test/formatter.spec.ts b/packages/code-formatter/test/formatter.spec.ts index 07f4c74faf..b7c8858218 100644 --- a/packages/code-formatter/test/formatter.spec.ts +++ b/packages/code-formatter/test/formatter.spec.ts @@ -11,7 +11,7 @@ describe('Formatting', () => { it('should preserve custom selectors with immediate descendants ', () => { const res = getDocumentFormatting( - '@custom-selector :--some-selector > :global(div) > :global(span);' + '@custom-selector :--some-selector > :global(div) > :global(span);', ); expect(res).to.eql('@custom-selector :--some-selector > :global(div) > :global(span);'); @@ -25,7 +25,7 @@ describe('Formatting', () => { ". type . ." 16px ". desc desc desc" 20px / 16px 3fr 2fr 4fr; - }`) + }`), ); expect(res).to.eql( @@ -36,7 +36,7 @@ describe('Formatting', () => { ". type . ." 16px ". desc desc desc" 20px / 16px 3fr 2fr 4fr; - }`) + }`), ); }); it('should preserve grid declarations', () => { @@ -48,7 +48,7 @@ describe('Formatting', () => { ". type . ." 16px ". desc desc desc" 20px / 16px 3fr 2fr 4fr; - }`) + }`), ); expect(res).to.eql( @@ -59,7 +59,7 @@ describe('Formatting', () => { ". type . ." 16px ". desc desc desc" 20px / 16px 3fr 2fr 4fr; - }`) + }`), ); }); @@ -84,7 +84,7 @@ describe('Formatting', () => { undefined, { indent_empty_lines: true, - } + }, ); expect(res).to.eql('.root {\n color: red;\n \n background: green;\n}'); @@ -112,7 +112,7 @@ describe('Formatting', () => { undefined, { max_preserve_newlines: 2, - } + }, ); expect(res).to.eql('.root {\n color: red;\n\n background: green;\n}'); @@ -132,7 +132,7 @@ describe('Formatting', () => { undefined, { preserve_newlines: true, - } + }, ); expect(res).to.eql('.root {\n color: red;\n\n\n background: green;\n}'); @@ -161,11 +161,11 @@ describe('Formatting', () => { undefined, { wrap_line_length: 10, - } + }, ); expect(res).to.eql( - '.background {\n background: repeating-linear-gradient(\n-45deg,\ntransparent 0,\ntransparent 25%,\ndodgerblue 0,\ndodgerblue 50%);\n}' + '.background {\n background: repeating-linear-gradient(\n-45deg,\ntransparent 0,\ntransparent 25%,\ndodgerblue 0,\ndodgerblue 50%);\n}', ); }); }); diff --git a/packages/core-test-kit/src/collect-ast.ts b/packages/core-test-kit/src/collect-ast.ts index 1c388de8ea..a8148bdd8e 100644 --- a/packages/core-test-kit/src/collect-ast.ts +++ b/packages/core-test-kit/src/collect-ast.ts @@ -2,12 +2,15 @@ import type * as postcss from 'postcss'; export function collectAst( root: postcss.Root, - collectCommentPrefix: Bucket[] + collectCommentPrefix: Bucket[], ) { - const collected = collectCommentPrefix.reduce((acc, name) => { - acc[name] = []; - return acc; - }, {} as Record); + const collected = collectCommentPrefix.reduce( + (acc, name) => { + acc[name] = []; + return acc; + }, + {} as Record, + ); const prefixRegex = `^(${collectCommentPrefix.join('|')})`; root.walk((node) => { const prevNode = node.prev(); diff --git a/packages/core-test-kit/src/diagnostics.ts b/packages/core-test-kit/src/diagnostics.ts index 2dde1e1109..1855f38677 100644 --- a/packages/core-test-kit/src/diagnostics.ts +++ b/packages/core-test-kit/src/diagnostics.ts @@ -51,17 +51,17 @@ export function matchDiagnostic( type: string, expectedWord: string, message: string, - label?: string + label?: string, ) => string; severityMismatch: ( type: string, expectedSeverity: string, actualSeverity: string, message: string, - label?: string + label?: string, ) => string; expectedNotFound: (type: string, message: string, label?: string) => string; - } + }, ): string { const diagnostics = type === `analyze` ? meta.diagnostics : meta.transformDiagnostics; if (!diagnostics) { @@ -100,7 +100,7 @@ export function matchDiagnostic( type, expected.location.word, expected.message, - expected.label + expected.label, ); foundPartialMatch(matchState); continue; @@ -114,7 +114,7 @@ export function matchDiagnostic( expectedSeverity, report.severity, expected.message, - expected.label + expected.label, ); foundPartialMatch(matchState); continue; @@ -167,7 +167,7 @@ export function findTestLocations(css: string) { export function expectAnalyzeDiagnostics( css: string, warnings: Diagnostic[], - { partial = false }: { partial?: boolean } = {} + { partial = false }: { partial?: boolean } = {}, ) { const source = findTestLocations(css); const root = safeParse(source.css); @@ -198,13 +198,13 @@ export function expectAnalyzeDiagnostics( if (expectedWarning.severity) { expect( report.severity, - `diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.severity}"` + `diagnostics severity mismatch, expected "${expectedWarning.severity}" but received "${report.severity}"`, ).to.equal(expectedWarning.severity); } }); expect(res.diagnostics.reports.length, 'diagnostics reports match').to.equal( - warnings.length + warnings.length, ); } return res; @@ -213,7 +213,7 @@ export function expectAnalyzeDiagnostics( function matchPartialDiagnostics( expectedList: Diagnostic[], diagnostics: Diagnostics, - locations: Record + locations: Record, ) { // ToDo: adding diagnostics numbered ids would really help for (const expectedWarning of expectedList) { @@ -236,7 +236,7 @@ function matchPartialDiagnostics( if (expectedWarning.severity) { expect( report.severity, - `${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}` + `${report.message}: severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`, ).to.equal(expectedWarning.severity); matches++; } @@ -260,7 +260,7 @@ function matchPartialDiagnostics( export function expectTransformDiagnostics( config: Config, expectedWarnings: Diagnostic[], - { partial = false }: { partial?: boolean } = {} + { partial = false }: { partial?: boolean } = {}, ): StylableResults { config.trimWS = false; @@ -277,7 +277,7 @@ export function expectTransformDiagnostics( if (expectedWarnings.length === 0 && diagnostics.reports.length !== 0) { expect( expectedWarnings.length, - `expected no diagnostics but received ${JSON.stringify(warningMessages, null, 2)}` + `expected no diagnostics but received ${JSON.stringify(warningMessages, null, 2)}`, ).to.equal(diagnostics.reports.length); } @@ -304,7 +304,7 @@ export function expectTransformDiagnostics( if (expectedWarning.severity) { expect( report.severity, - `diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}` + `diagnostics severity mismatch, expected ${expectedWarning.severity} but received ${report.severity}`, ).to.equal(expectedWarning.severity); } } @@ -313,8 +313,8 @@ export function expectTransformDiagnostics( `expected diagnostics: ${JSON.stringify( expectedWarnings.map((d) => d.message), null, - 2 - )}, but received ${JSON.stringify(warningMessages, null, 2)}` + 2, + )}, but received ${JSON.stringify(warningMessages, null, 2)}`, ).to.equal(diagnostics.reports.length); } @@ -326,14 +326,14 @@ export function shouldReportNoDiagnostics(meta: StylableMeta, checkTransformDiag expect( processReports.length, - `processing diagnostics: ${processReports.map((r) => r.message)}` + `processing diagnostics: ${processReports.map((r) => r.message)}`, ).to.equal(0); if (meta.transformDiagnostics && checkTransformDiagnostics) { const transformerReports = meta.transformDiagnostics.reports; expect( transformerReports.length, - `transforming diagnostics: ${transformerReports.map((r) => r.message)}` + `transforming diagnostics: ${transformerReports.map((r) => r.message)}`, ).to.equal(0); } } @@ -345,7 +345,7 @@ export type UnwrapDiagnosticMessage = { }; export function diagnosticBankReportToStrings( - bank: T + bank: T, ): UnwrapDiagnosticMessage { const cleaned = {} as UnwrapDiagnosticMessage; diff --git a/packages/core-test-kit/src/generate-test-util.ts b/packages/core-test-kit/src/generate-test-util.ts index 816a0499c2..cde4d72c60 100644 --- a/packages/core-test-kit/src/generate-test-util.ts +++ b/packages/core-test-kit/src/generate-test-util.ts @@ -87,7 +87,7 @@ export function createTransformer( replaceValueHook, postProcessor, onResolve = (resolved) => resolved, - }: CreateTransformerOptions = {} + }: CreateTransformerOptions = {}, ): StylableTransformer { const { requireModule, fileProcessor, resolvePath } = generateInfra(config, diagnostics); @@ -107,7 +107,7 @@ export function createTransformer( export function processSource( source: string, options: { from?: string } = {}, - resolveNamespace?: typeof processNamespace + resolveNamespace?: typeof processNamespace, ) { return new StylableProcessor(new Diagnostics(), resolveNamespace, { ...defaultFeatureFlags, @@ -115,7 +115,7 @@ export function processSource( } export function createProcess( - fileProcessor: FileProcessor + fileProcessor: FileProcessor, ): (path: string) => StylableMeta { return (path: string) => fileProcessor.process(path); } @@ -124,7 +124,7 @@ export function createResolveExtendsResults( fileSystem: IFileSystem, fileToProcess: string, classNameToLookup: string, - isElement = false + isElement = false, ) { const stylable = new Stylable({ fileSystem, @@ -134,13 +134,13 @@ export function createResolveExtendsResults( return stylable.resolver.resolveExtends( stylable.analyze(fileToProcess), classNameToLookup, - isElement + isElement, ); } export function generateStylableResult( config: Config, - diagnostics: Diagnostics = new Diagnostics() + diagnostics: Diagnostics = new Diagnostics(), ) { const { entry } = config; if (!isAbsolute(entry || '')) { @@ -160,7 +160,7 @@ export function generateStylableExports(config: Config) { export function generateStylableEnvironment( content: IDirectoryContents, - stylableConfig: Partial> = {} + stylableConfig: Partial> = {}, ) { const fs = createMemoryFs(content); diff --git a/packages/core-test-kit/src/inline-expectation.ts b/packages/core-test-kit/src/inline-expectation.ts index 77b53313e8..10929b74c2 100644 --- a/packages/core-test-kit/src/inline-expectation.ts +++ b/packages/core-test-kit/src/inline-expectation.ts @@ -118,7 +118,7 @@ export function testInlineExpects(result: postcss.Root | Context, expectedTestIn expectation: testInput.trim(), errors: [ testInlineExpectsErrors.deprecatedRootInputNotSupported( - testScope + testInput + testScope + testInput, ), ], hasMissingDiagnostic: false, @@ -130,7 +130,7 @@ export function testInlineExpects(result: postcss.Root | Context, expectedTestIn context, testInput.trim(), isRemoved ? undefined : nodeTarget, - nodeSrc + nodeSrc, ); result.type = testScope; errors.push(...result.errors); @@ -157,7 +157,7 @@ function checkTest( context: Context, expectation: string, targetNode: AST | undefined, - srcNode: AST + srcNode: AST, ): Test { const type = srcNode?.type || targetNode?.type; switch (type) { @@ -180,7 +180,7 @@ function ruleTest( context: Context, expectation: string, targetNode: AST | undefined, - srcNode: AST + srcNode: AST, ): Test { const result: Test = { type: `@rule`, @@ -189,7 +189,7 @@ function ruleTest( hasMissingDiagnostic: false, }; const { msg, ruleIndex, expectedSelector, expectedBody } = expectation.match( - /(?\([^)]*\))*(\[(?\d+)\])*(?[^{}]*)\s*(?.*)/s + /(?\([^)]*\))*(\[(?\d+)\])*(?[^{}]*)\s*(?.*)/s, )!.groups!; const prefix = msg ? msg + `: ` : ``; if (!targetNode) { @@ -202,7 +202,7 @@ function ruleTest( if (ruleIndex) { if (targetNode?.type !== `rule`) { result.errors.push( - `mixed-in expectation is only supported for CSS Rule, not ${targetNode?.type}` + `mixed-in expectation is only supported for CSS Rule, not ${targetNode?.type}`, ); return result; } else { @@ -228,7 +228,7 @@ function ruleTest( expectedDeclarations.push([prop.trim(), value.trim()]); } else { result.errors.push( - testInlineExpectsErrors.ruleMalformedDecl(decl, expectation) + testInlineExpectsErrors.ruleMalformedDecl(decl, expectation), ); } } @@ -237,7 +237,11 @@ function ruleTest( if (testNode.selector !== expectedSelector.trim()) { result.errors.push( - testInlineExpectsErrors.selector(expectedSelector.trim(), testNode.selector, prefix) + testInlineExpectsErrors.selector( + expectedSelector.trim(), + testNode.selector, + prefix, + ), ); } if (declarationCheck === `full`) { @@ -254,8 +258,8 @@ function ruleTest( expectedDecl, actualDecl, testNode.selector, - prefix - ) + prefix, + ), ); } } @@ -266,7 +270,7 @@ function ruleTest( context, expectation.replace(`[${ruleIndex}]`, ``), testNode, - null as unknown as AST + null as unknown as AST, ); } else { // unsupported mixed-in node test @@ -278,7 +282,7 @@ function atRuleTest( _context: Context, expectation: string, targetNode: AST | undefined, - srcNode: AST + srcNode: AST, ): Test { const result: Test = { type: `@atrule`, @@ -286,8 +290,9 @@ function atRuleTest( errors: [], hasMissingDiagnostic: false, }; - const { msg, expectedParams } = expectation.match(/(?\([^)]*\))*(?.*)/)! - .groups!; + const { msg, expectedParams } = expectation.match( + /(?\([^)]*\))*(?.*)/, + )!.groups!; if (expectedParams.match(/^\[\d+\]/)) { result.errors.push(testInlineExpectsErrors.atRuleMultiTest(expectation)); return result; @@ -302,8 +307,8 @@ function atRuleTest( testInlineExpectsErrors.atruleParams( expectedParams.trim(), targetNode.params, - prefix - ) + prefix, + ), ); } } else { @@ -315,7 +320,7 @@ function declTest( _context: Context, expectation: string, targetNode: AST | undefined, - srcNode: AST + srcNode: AST, ): Test { const result: Test = { type: `@decl`, @@ -325,7 +330,7 @@ function declTest( }; // eslint-disable-next-line prefer-const let { label, prop, colon, value } = expectation.match( - /(?