Skip to content

Commit

Permalink
refactor: reformat sources using latest prettier
Browse files Browse the repository at this point in the history
also added prettier to root package.json, so specific version is used by both `npm run prettify` and vscode plugin (it loads the version in node_modules if specified in root package.json)
  • Loading branch information
AviVahl committed Aug 28, 2024
1 parent f245fb6 commit 135229e
Show file tree
Hide file tree
Showing 376 changed files with 2,860 additions and 2,747 deletions.
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/build-tools/src/calc-depth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function calcDepth<T>(
module: T,
context: CalcDepthContext<T>,
path: T[] = [],
cache = new Map<T, number>()
cache = new Map<T, number>(),
): number {
let cssDepth = 0;
if (cache.has(module)) {
Expand Down Expand Up @@ -57,7 +57,7 @@ export function getCSSViewModule<T>(module: T, context: CalcDepthContext<T>) {

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];
Expand Down
6 changes: 3 additions & 3 deletions packages/build-tools/src/has-imported-side-effects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export function collectImportsWithSideEffects(
stylable: Stylable,
meta: StylableMeta,
visit: (contextMeta: StylableMeta, absPath: string, hasSideEffects: boolean) => void,
visited: Set<string> = new Set()
visited: Set<string> = new Set(),
) {
for (const importData of meta.getImportStatements()) {
// attempt to resolve the request through stylable resolveModule,
Expand All @@ -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
Expand Down Expand Up @@ -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 &&
Expand Down
12 changes: 6 additions & 6 deletions packages/build-tools/src/load-stylable-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { pathToFileURL } from 'url';

export function loadStylableConfig<T>(
context: string,
extract: (config: any) => T
extract: (config: any) => T,
): { path: string; config: T } | undefined {
const path =
findConfig('stylable.config.js', { cwd: context }) ??
Expand All @@ -14,12 +14,12 @@ export function loadStylableConfig<T>(
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 {
Expand All @@ -36,7 +36,7 @@ const esmImport: (url: URL) => any = eval(`(path) => import(path)`);

export async function loadStylableConfigEsm<T>(
context: string,
extract: (config: any) => T
extract: (config: any) => T,
): Promise<{ path: string; config: T } | undefined> {
const path =
findConfig('stylable.config.js', { cwd: context }) ??
Expand All @@ -47,12 +47,12 @@ export async function loadStylableConfigEsm<T>(
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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/build-tools/src/process-url-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export function processUrlDependencies({
onUrl(functionNode);
}
},
true
true,
);
});
return urls;
Expand Down
2 changes: 1 addition & 1 deletion packages/build-tools/src/sort-modules-by-depth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export function sortModulesByDepth<T>(
modules: Array<T>,
getDepth: (m: T) => number,
getID: (m: T) => string,
factor = 1
factor = 1,
) {
return modules.sort((m1, m2) => {
const depthDiff = getDepth(m2) - getDepth(m1);
Expand Down
8 changes: 4 additions & 4 deletions packages/build-tools/test/sort-modules-by-depth.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('sort-modules-by-depth', () => {
{ id: 'a1', depth: 1 },
],
({ depth }) => depth,
({ id }) => id
({ id }) => id,
);

expect(sorted).to.eql([
Expand All @@ -31,7 +31,7 @@ describe('sort-modules-by-depth', () => {
{ id: 'a1', depth: 1 },
],
({ depth }) => depth,
({ id }) => id
({ id }) => id,
);

expect(sorted).to.eql([
Expand All @@ -51,7 +51,7 @@ describe('sort-modules-by-depth', () => {
{ id: 'a0', depth: 0 },
],
({ depth }) => depth,
({ id }) => id
({ id }) => id,
);

expect(sorted).to.eql([
Expand All @@ -72,7 +72,7 @@ describe('sort-modules-by-depth', () => {
],
({ depth }) => depth,
({ id }) => id,
-1
-1,
);

expect(sorted).to.eql([
Expand Down
14 changes: 8 additions & 6 deletions packages/cli/src/base-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
);
}

Expand All @@ -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);
Expand Down Expand Up @@ -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<Record<string, string>>(
(acc, varName) => {
acc[varName] = `--${rootExport}__${varName.slice(2)}`;
return acc;
},
{}
{},
);
const keyframes = Object.keys(STSymbol.getAllByType(meta, `keyframes`)).reduce<
Record<string, string>
Expand Down
24 changes: 12 additions & 12 deletions packages/cli/src/build-single-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -105,7 +105,7 @@ export function buildSingleFile({
removeUnusedComponents: false,
},
res,
{}
{},
);
}

Expand All @@ -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;
Expand All @@ -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!;

Expand Down Expand Up @@ -174,7 +174,7 @@ export function buildSingleFile({
id: res.meta.namespace,
runtimeId: format,
}
: undefined
: undefined,
);
const outFilePath = targetFilePath + ext;
generated.add(outFilePath);
Expand All @@ -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
Expand Down Expand Up @@ -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}`);

Expand All @@ -298,7 +298,7 @@ export function buildDTS({
if (dtsSourceMap !== false) {
const relativeTargetFilePath = relative(
dirname(targetFilePath),
sourceFilePath || targetFilePath
sourceFilePath || targetFilePath,
);

const dtsMappingContent = generateDTSSourceMap(
Expand All @@ -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';
Expand All @@ -317,7 +317,7 @@ export function buildDTS({

tryRun(
() => writeFileSync(dtsMapPath, dtsMappingContent),
`Write File Error: ${dtsMapPath}`
`Write File Error: ${dtsMapPath}`,
);
}
}
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/build-stylable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export async function buildStylable(
resolveModule,
configFilePath,
watchOptions = {},
}: BuildStylableContext = {}
}: BuildStylableContext = {},
) {
const { config } = resolveConfig(rootDir, fs, configFilePath) || {};
validateDefaultConfig(config?.defaultConfig);
Expand All @@ -76,15 +76,15 @@ export async function buildStylable(
projectRoot,
i,
options.length > 1,
projects.length > 1
projects.length > 1,
);

log('[Project]', projectRoot, buildOptions);

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,
);
}

Expand Down
Loading

0 comments on commit 135229e

Please sign in to comment.