Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: make imports "type": "module" ready #2978

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
13 changes: 8 additions & 5 deletions packages/build-tools/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
export { processUrlDependencies } from './process-url-dependencies';
export { hasImportedSideEffects, collectImportsWithSideEffects } from './has-imported-side-effects';
export { sortModulesByDepth } from './sort-modules-by-depth';
export { loadStylableConfig, loadStylableConfigEsm } from './load-stylable-config';
export { CalcDepthContext, calcDepth, getCSSViewModule } from './calc-depth';
export { processUrlDependencies } from './process-url-dependencies.js';
export {
hasImportedSideEffects,
collectImportsWithSideEffects,
} from './has-imported-side-effects.js';
export { sortModulesByDepth } from './sort-modules-by-depth.js';
export { loadStylableConfig, loadStylableConfigEsm } from './load-stylable-config.js';
export { CalcDepthContext, calcDepth, getCSSViewModule } from './calc-depth.js';
4 changes: 2 additions & 2 deletions packages/cli/src/base-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type { Stylable } from '@stylable/core';
import { STSymbol } from '@stylable/core/dist/index-internal';
import camelcase from 'lodash.camelcase';
import upperfirst from 'lodash.upperfirst';
import { normalizeRelative, ensureDirectory, tryRun } from './build-tools';
import { createDefaultLogger, Log } from './logger';
import { normalizeRelative, ensureDirectory, tryRun } from './build-tools.js';
import { createDefaultLogger, Log } from './logger.js';

export interface ReExports {
root: string;
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/build-single-file.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import { generateDTSContent, generateDTSSourceMap } from '@stylable/module-utils
import { StylableOptimizer } from '@stylable/optimizer';
import type { IFileSystem } from '@file-services/types';
import { hasImportedSideEffects, processUrlDependencies } from '@stylable/build-tools';
import { ensureDirectory, tryRun } from './build-tools';
import { nameTemplate } from './name-template';
import type { Log } from './logger';
import { DiagnosticsManager, DiagnosticsMode } from './diagnostics-manager';
import type { CLIDiagnostic } from './report-diagnostics';
import { errorMessages } from './messages';
import type { ModuleFormats } from './types';
import { fileToDataUri } from './file-to-data-uri';
import { ensureDirectory, tryRun } from './build-tools.js';
import { nameTemplate } from './name-template.js';
import type { Log } from './logger.js';
import { DiagnosticsManager, DiagnosticsMode } from './diagnostics-manager.js';
import type { CLIDiagnostic } from './report-diagnostics.js';
import { errorMessages } from './messages.js';
import type { ModuleFormats } from './types.js';
import { fileToDataUri } from './file-to-data-uri.js';

export interface BuildCommonOptions {
fullOutDir: string;
Expand Down
16 changes: 8 additions & 8 deletions packages/cli/src/build-stylable.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { nodeFs } from '@file-services/node';
import { Stylable, StylableConfig } from '@stylable/core';
import { StylableResolverCache, validateDefaultConfig } from '@stylable/core/dist/index-internal';
import { build } from './build';
import { projectsConfig, resolveConfig } from './config/projects-config';
import { build } from './build.js';
import { projectsConfig, resolveConfig } from './config/projects-config.js';
import {
createBuildIdentifier,
createDefaultOptions,
hasStylableCSSOutput,
} from './config/resolve-options';
import { DiagnosticsManager } from './diagnostics-manager';
import { createDefaultLogger, levels } from './logger';
import type { BuildContext, BuildOptions } from './types';
import { WatchHandler } from './watch-handler';
import { createWatchService } from './watch-service';
} from './config/resolve-options.js';
import { DiagnosticsManager } from './diagnostics-manager.js';
import { createDefaultLogger, levels } from './logger.js';
import type { BuildContext, BuildOptions } from './types.js';
import { WatchHandler } from './watch-handler.js';
import { createWatchService } from './watch-service.js';

export interface BuildStylableContext
extends Partial<Pick<BuildContext, 'fs' | 'watch' | 'log'>>,
Expand Down
22 changes: 11 additions & 11 deletions packages/cli/src/build.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { fixRelativeUrls, tryCollectImportsDeep } from '@stylable/core/dist/index-internal';
import type { BuildContext, BuildOptions, ModuleFormats } from './types';
import { IndexGenerator as BaseIndexGenerator } from './base-generator';
import { generateManifest } from './generate-manifest';
import { handleAssets } from './handle-assets';
import { buildSingleFile, removeBuildProducts } from './build-single-file';
import { DirectoryProcessService } from './directory-process-service/directory-process-service';
import { DiagnosticsManager } from './diagnostics-manager';
import type { CLIDiagnostic } from './report-diagnostics';
import { tryRun } from './build-tools';
import { errorMessages, buildMessages } from './messages';
import type { BuildContext, BuildOptions, ModuleFormats } from './types.js';
import { IndexGenerator as BaseIndexGenerator } from './base-generator.js';
import { generateManifest } from './generate-manifest.js';
import { handleAssets } from './handle-assets.js';
import { buildSingleFile, removeBuildProducts } from './build-single-file.js';
import { DirectoryProcessService } from './directory-process-service/directory-process-service.js';
import { DiagnosticsManager } from './diagnostics-manager.js';
import type { CLIDiagnostic } from './report-diagnostics.js';
import { tryRun } from './build-tools.js';
import { errorMessages, buildMessages } from './messages.js';
import postcss from 'postcss';
import { sortModulesByDepth } from '@stylable/build-tools';
import { StylableOptimizer } from '@stylable/optimizer';
import type { Stylable } from '@stylable/core';
import type { IFileSystem } from '@file-services/types';
import { createWatchService } from './watch-service';
import { createWatchService } from './watch-service.js';

export function build(
{
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/cli-codemod.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
#!/usr/bin/env node

import fs from '@file-services/node';
import { nodeFs as fs } from '@file-services/node';
import { resolve } from 'path';
import yargs from 'yargs';
import { codeMods } from './code-mods/code-mods';
import { codeMods } from './code-mods/code-mods.js';
import {
loadExternalCodemods,
loadBuiltInCodemods,
registeredMods,
} from './code-mods/load-codemods';
import { createLogger } from './logger';
import type { CodeMod } from './code-mods/types';
} from './code-mods/load-codemods.js';
import { createLogger } from './logger.js';
import type { CodeMod } from './code-mods/types.js';

const argv = yargs
.option('rootDir', {
Expand Down
10 changes: 7 additions & 3 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
#!/usr/bin/env node
import { nodeFs as fs } from '@file-services/node';
import { buildStylable } from './build-stylable';
import { createDefaultOptions, getCliArguments, resolveCliOptions } from './config/resolve-options';
import { createLogger } from './logger';
import { buildStylable } from './build-stylable.js';
import {
createDefaultOptions,
getCliArguments,
resolveCliOptions,
} from './config/resolve-options.js';
import { createLogger } from './logger.js';

const argv = getCliArguments();
const { resolve } = fs;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/code-format.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/usr/bin/env node
import yargs from 'yargs';
import fs from '@file-services/node';
import { nodeFs as fs } from '@file-services/node';
import { getDocumentFormatting, formatCSS } from '@stylable/code-formatter';
import { createLogger } from './logger';
import { createLogger } from './logger.js';

const { join, writeFileSync } = fs;

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/code-mods/apply-code-mods.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Diagnostic, Diagnostics } from '@stylable/core';
import postcss, { parse, CssSyntaxError } from 'postcss';
import type { CodeMod, ApplyCodeModsResult } from './types';
import type { CodeMod, ApplyCodeModsResult } from './types.js';

export function applyCodeMods(
filePath: string,
Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/code-mods/code-mods.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { FileSystem, findFiles } from '@stylable/node';
import { applyCodeMods } from './apply-code-mods';
import { applyCodeMods } from './apply-code-mods.js';
import { relative, join } from 'path';
import type { ApplyCodeModsResult, ApplyCodeModsSuccess, CodeMod } from './types';
import type { Log } from '../logger';
import type { ApplyCodeModsResult, ApplyCodeModsSuccess, CodeMod } from './types.js';
import type { Log } from '../logger.js';
import type { Diagnostic } from '@stylable/core';

export interface CodeModsOptions {
Expand Down
10 changes: 5 additions & 5 deletions packages/cli/src/code-mods/load-codemods.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { CodeMod } from './types';
import type { Log } from '../logger';
import type { CodeMod } from './types.js';
import type { Log } from '../logger.js';

// Builtin codemods
import { stImportToAtImport } from './st-import-to-at-import';
import { stGlobalCustomPropertyToAtProperty } from './st-global-custom-property-to-at-property';
import { namespaceToStNamespace } from './namespace-to-st-namespace';
import { stImportToAtImport } from './st-import-to-at-import.js';
import { stGlobalCustomPropertyToAtProperty } from './st-global-custom-property-to-at-property.js';
import { namespaceToStNamespace } from './namespace-to-st-namespace.js';

export const registeredMods: Map<string, CodeMod> = new Map([
['st-import-to-at-import', stImportToAtImport],
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/code-mods/namespace-to-st-namespace.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { STNamespace } from '@stylable/core/dist/index-internal';
import type * as postcss from 'postcss';
import type { CodeMod } from './types';
import type { CodeMod } from './types.js';

export const namespaceToStNamespace: CodeMod = ({ ast }) => {
let changed = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { CSSVarSymbol, Diagnostics, validateCustomPropertyName } from '@stylable/core';
import { CSSCustomProperty } from '@stylable/core/dist/index-internal';
import type { AtRule } from 'postcss';
import type { CodeMod } from './types';
import type { CodeMod } from './types.js';

export const stGlobalCustomPropertyToAtProperty: CodeMod = ({ ast, diagnostics, postcss }) => {
let changed = false;
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/code-mods/st-import-to-at-import.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { parsePseudoImport, createAtImportProps } from '@stylable/core/dist/index-internal';
import type { CodeMod } from './types';
import type { CodeMod } from './types.js';

export const stImportToAtImport: CodeMod = ({ ast, diagnostics, postcss }) => {
let changed = false;
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/config/process-projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import type {
ProjectEntryValue,
ProjectEntryValues,
RawProjectEntity,
} from '../types';
import { createDefaultOptions, mergeBuildOptions, validateOptions } from './resolve-options';
} from '../types.js';
import { createDefaultOptions, mergeBuildOptions, validateOptions } from './resolve-options.js';

interface ProcessProjectsOptions {
defaultOptions?: BuildOptions;
Expand Down
12 changes: 6 additions & 6 deletions packages/cli/src/config/projects-config.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { loadStylableConfig } from '@stylable/build-tools';
import type { BuildOptions } from '../types';
import { tryRun } from '../build-tools';
import type { BuildOptions } from '../types.js';
import { tryRun } from '../build-tools.js';
import type {
Configuration,
ConfigurationProvider,
Expand All @@ -9,10 +9,10 @@ import type {
ResolveProjectsContext,
ResolveRequests,
STCProjects,
} from '../types';
import { processProjects } from './process-projects';
import { createDefaultOptions, mergeBuildOptions, validateOptions } from './resolve-options';
import { resolveNpmRequests } from './resolve-requests';
} from '../types.js';
import { processProjects } from './process-projects.js';
import { createDefaultOptions, mergeBuildOptions, validateOptions } from './resolve-options.js';
import { resolveNpmRequests } from './resolve-requests.js';
import type { StylableConfig } from '@stylable/core';
import type { IFileSystem } from '@file-services/types';

Expand Down
6 changes: 3 additions & 3 deletions packages/cli/src/config/resolve-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { nodeFs } from '@file-services/node';
import type { Arguments } from 'yargs';
import yargs from 'yargs';
import { createGenerator } from '../build';
import { removeUndefined } from '../helpers';
import type { CliArguments, BuildOptions, PartialBuildOptions } from '../types';
import { createGenerator } from '../build.js';
import { removeUndefined } from '../helpers.js';
import type { CliArguments, BuildOptions, PartialBuildOptions } from '../types.js';

const { join } = nodeFs;

Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/config/resolve-requests.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import fs from '@file-services/node';
import { nodeFs as fs } from '@file-services/node';
import {
INpmPackage,
resolveWorkspacePackages,
sortPackagesByDepth,
} from '@wixc3/resolve-directory-context';
import type { RawProjectEntity, ResolveRequests } from '../types';
import type { RawProjectEntity, ResolveRequests } from '../types.js';

export const resolveNpmRequests: ResolveRequests = (entities, { rootDir }) => {
const entitiesMap = new Map<string, RawProjectEntity>();
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/diagnostics-manager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { createDefaultLogger, Log } from './logger';
import { CLIDiagnostic, DiagnosticMessages, reportDiagnostics } from './report-diagnostics';
import { createDefaultLogger, Log } from './logger.js';
import { CLIDiagnostic, DiagnosticMessages, reportDiagnostics } from './report-diagnostics.js';

export type DiagnosticsMode = 'strict' | 'loose';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { IFileSystem, IWatchEvent } from '@file-services/types';
import { createWatchEvent, type WatchService } from '../watch-service';
import { directoryDeepChildren, DirectoryItem } from './walk-fs';
import { createWatchEvent, type WatchService } from '../watch-service.js';
import { directoryDeepChildren, DirectoryItem } from './walk-fs.js';

export interface DirectoryProcessServiceOptions {
processFiles?(
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/src/generate-manifest.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Stylable } from '@stylable/core';
import { dirname, relative } from 'path';
import { ensureDirectory, tryRun } from './build-tools';
import type { Log } from './logger';
import { ensureDirectory, tryRun } from './build-tools.js';
import type { Log } from './logger.js';

export function generateManifest(
rootDir: string,
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/handle-assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { IFileSystem } from '@file-services/types';
import { ensureDirectory } from './build-tools';
import { ensureDirectory } from './build-tools.js';

export function handleAssets(
assets: Set<string>,
Expand Down
26 changes: 13 additions & 13 deletions packages/cli/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
export { build } from './build';
export { Log, createLogger } from './logger';
export { build } from './build.js';
export { Log, createLogger } from './logger.js';
export {
IndexGenerator,
IndexGeneratorParameters,
ReExports,
reExportsAllSymbols,
} from './base-generator';
} from './base-generator.js';
export {
BuildOptions,
Configuration,
Expand All @@ -14,16 +14,16 @@ export {
ResolveRequests,
typedConfiguration,
stcConfig,
} from './types';
export { resolveConfig } from './config/projects-config';
export type { WatchHandler } from './watch-handler';
export { DiagnosticsManager } from './diagnostics-manager';
} from './types.js';
export { resolveConfig } from './config/projects-config.js';
export type { WatchHandler } from './watch-handler.js';
export { DiagnosticsManager } from './diagnostics-manager.js';
export {
DirectoryProcessService,
DirectoryProcessServiceOptions,
} from './directory-process-service/directory-process-service';
export { STCBuilder } from './stc-builder';
export { BuildStylableContext, buildStylable } from './build-stylable';
export { buildDTS } from './build-single-file';
export type { CodeMod } from './code-mods/types';
export { createWatchService, createWatchEvent, type WatchService } from './watch-service';
} from './directory-process-service/directory-process-service.js';
export { STCBuilder } from './stc-builder.js';
export { BuildStylableContext, buildStylable } from './build-stylable.js';
export { buildDTS } from './build-single-file.js';
export type { CodeMod } from './code-mods/types.js';
export { createWatchService, createWatchEvent, type WatchService } from './watch-service.js';
2 changes: 1 addition & 1 deletion packages/cli/src/report-diagnostics.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Diagnostic } from '@stylable/core';
import { levels, Log } from './logger';
import { levels, Log } from './logger.js';

export interface CLIDiagnostic extends Diagnostic {
line?: number;
Expand Down
14 changes: 7 additions & 7 deletions packages/cli/src/stc-builder.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { nodeFs } from '@file-services/node';
import { buildStylable } from './build-stylable';
import { DiagnosticsManager } from './diagnostics-manager';
import { createLogger, Log } from './logger';
import { buildStylable } from './build-stylable.js';
import { DiagnosticsManager } from './diagnostics-manager.js';
import { createLogger, Log } from './logger.js';
import type { IFileSystem } from '@file-services/types';
import type { DiagnosticMessages } from './report-diagnostics';
import type { STCProjects } from './types';
import type { WatchHandler } from './watch-handler';
import type { DiagnosticMessages } from './report-diagnostics.js';
import type { STCProjects } from './types.js';
import type { WatchHandler } from './watch-handler.js';
import {
DiagnosticsMode,
EmitDiagnosticsContext,
reportDiagnostic,
} from '@stylable/core/dist/index-internal';
import { createWatchEvent } from './watch-service';
import { createWatchEvent } from './watch-service.js';

export type STCBuilderFileSystem = Pick<IFileSystem, 'existsSync' | 'realpathSync' | 'join'>;

Expand Down
8 changes: 4 additions & 4 deletions packages/cli/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { IFileSystem } from '@file-services/types';
import type { Stylable } from '@stylable/core';
import type { IndexGenerator } from './base-generator';
import type { DiagnosticsManager, DiagnosticsMode } from './diagnostics-manager';
import type { Log } from './logger';
import type { WatchService } from './watch-service';
import type { IndexGenerator } from './base-generator.js';
import type { DiagnosticsManager, DiagnosticsMode } from './diagnostics-manager.js';
import type { Log } from './logger.js';
import type { WatchService } from './watch-service.js';

export type PartialBuildOptions = Partial<BuildOptions>;

Expand Down
Loading
Loading