From 8134ecf42e1db61d2a3fe0f69b13989e207a5123 Mon Sep 17 00:00:00 2001 From: Barak Date: Sun, 1 Oct 2023 11:25:27 +0300 Subject: [PATCH] chore: rename to createWebpackResolver --- packages/cli/test/cli.spec.ts | 8 ++++---- .../experimental-loader/src/stylable-transform-loader.ts | 4 ++-- .../webpack-extensions/src/stylable-manifest-plugin.ts | 4 ++-- .../webpack-extensions/src/stylable-metadata-loader.ts | 4 ++-- packages/webpack-plugin/src/index.ts | 2 +- packages/webpack-plugin/src/legacy-module-resolver.ts | 2 +- packages/webpack-plugin/src/plugin.ts | 4 ++-- .../test/e2e/projects/native-css/webpack.config.js | 4 ++-- .../stylable.config.js | 4 ++-- .../webpack.config.js | 4 ++-- .../stylable-config-resolver-override/stylable.config.js | 6 +++--- .../projects/stylable-config-resolver/stylable.config.js | 4 ++-- 12 files changed, 25 insertions(+), 25 deletions(-) diff --git a/packages/cli/test/cli.spec.ts b/packages/cli/test/cli.spec.ts index 7345985e0..3da9a9ae1 100644 --- a/packages/cli/test/cli.spec.ts +++ b/packages/cli/test/cli.spec.ts @@ -564,12 +564,12 @@ describe('Stylable Cli', function () { 'package.json': `{"name": "test", "version": "0.0.0"}`, 'stylable.config.js': ` const { resolve } = require('node:path'); - const { createLegacyResolver } = require('@stylable/webpack-plugin'); + const { createWebpackResolver } = require('@stylable/webpack-plugin'); module.exports = { defaultConfig(fs) { return { - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { alias: { '@colors': resolve(__dirname, './colors') } @@ -618,12 +618,12 @@ describe('Stylable Cli', function () { 'stylable.config.js': ` const { join } = require('path'); const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin'); - const { createLegacyResolver } = require('@stylable/webpack-plugin'); + const { createWebpackResolver } = require('@stylable/webpack-plugin'); module.exports = { defaultConfig(fs) { return { - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { plugins: [new TsconfigPathsPlugin({ configFile: join(${JSON.stringify( tempDir.path )},'tsconfig.json') })], diff --git a/packages/experimental-loader/src/stylable-transform-loader.ts b/packages/experimental-loader/src/stylable-transform-loader.ts index d17152dfc..6efb0dcde 100644 --- a/packages/experimental-loader/src/stylable-transform-loader.ts +++ b/packages/experimental-loader/src/stylable-transform-loader.ts @@ -9,7 +9,7 @@ import { Warning, CssSyntaxError } from './warning'; import { getStylable } from './cached-stylable-factory'; import { createRuntimeTargetCode } from './create-runtime-target-code'; import { addBuildInfo } from './add-build-info'; -import { createLegacyResolver } from '@stylable/webpack-plugin'; +import { createWebpackResolver } from '@stylable/webpack-plugin'; import type { LoaderDefinition, LoaderContext } from 'webpack'; // TODO: maybe adopt the code @@ -65,7 +65,7 @@ const stylableLoader: LoaderDefinition = function (content) { }; const mode = this._compiler!.options.mode === 'development' ? 'development' : 'production'; - const resolveModule = createLegacyResolver( + const resolveModule = createWebpackResolver( this.fs as any, this._compiler!.options.resolve as any ); diff --git a/packages/webpack-extensions/src/stylable-manifest-plugin.ts b/packages/webpack-extensions/src/stylable-manifest-plugin.ts index 5aa9ffa6f..8a769d7f2 100644 --- a/packages/webpack-extensions/src/stylable-manifest-plugin.ts +++ b/packages/webpack-extensions/src/stylable-manifest-plugin.ts @@ -1,5 +1,5 @@ import { Stylable, StylableMeta } from '@stylable/core'; -import { createLegacyResolver } from '@stylable/webpack-plugin'; +import { createWebpackResolver } from '@stylable/webpack-plugin'; import { STSymbol } from '@stylable/core/dist/index-internal'; import { resolveNamespace } from '@stylable/node'; import { createMetadataForStylesheet } from './create-metadata-stylesheet'; @@ -56,7 +56,7 @@ export class StylableManifestPlugin { this.options = Object.assign({}, defaultOptions, options); } public apply(compiler: Compiler) { - const resolveModule = createLegacyResolver(compiler.inputFileSystem as any, { + const resolveModule = createWebpackResolver(compiler.inputFileSystem as any, { ...compiler.options.resolve as any, extensions: [], }); diff --git a/packages/webpack-extensions/src/stylable-metadata-loader.ts b/packages/webpack-extensions/src/stylable-metadata-loader.ts index 31ba7b415..460ad57d8 100644 --- a/packages/webpack-extensions/src/stylable-metadata-loader.ts +++ b/packages/webpack-extensions/src/stylable-metadata-loader.ts @@ -1,5 +1,5 @@ import { Stylable, processNamespace } from '@stylable/core'; -import { createStylableResolverCacheMap, createLegacyResolver } from '@stylable/webpack-plugin'; +import { createStylableResolverCacheMap, createWebpackResolver } from '@stylable/webpack-plugin'; import findConfig from 'find-config'; import type { LoaderDefinition, LoaderContext } from 'webpack'; import { createMetadataForStylesheet } from './create-metadata-stylesheet'; @@ -49,7 +49,7 @@ function createStylable( if (!loader._compiler) { throw new Error('Stylable metadata loader requires a compiler instance'); } - const resolveModule = createLegacyResolver(loader.fs as any, { + const resolveModule = createWebpackResolver(loader.fs as any, { ...(loader._compiler.options.resolve as any), extensions: [], }); diff --git a/packages/webpack-plugin/src/index.ts b/packages/webpack-plugin/src/index.ts index c742a8610..74f9422ce 100644 --- a/packages/webpack-plugin/src/index.ts +++ b/packages/webpack-plugin/src/index.ts @@ -54,4 +54,4 @@ export { WebpackCreateHash, WebpackOutputOptions, } from './types'; -export { createLegacyResolver } from './legacy-module-resolver'; +export { createWebpackResolver } from './legacy-module-resolver'; diff --git a/packages/webpack-plugin/src/legacy-module-resolver.ts b/packages/webpack-plugin/src/legacy-module-resolver.ts index 5426b4e52..db00d7f07 100644 --- a/packages/webpack-plugin/src/legacy-module-resolver.ts +++ b/packages/webpack-plugin/src/legacy-module-resolver.ts @@ -21,7 +21,7 @@ function bundleSafeRequireExtensions(): string[] { const resolverContext = {}; -export function createLegacyResolver(fileSystem: ResolveOptions['fileSystem'], resolveOptions: Partial) { +export function createWebpackResolver(fileSystem: ResolveOptions['fileSystem'], resolveOptions: Partial) { const extensions = resolveOptions.extensions && resolveOptions.extensions.length ? resolveOptions.extensions diff --git a/packages/webpack-plugin/src/plugin.ts b/packages/webpack-plugin/src/plugin.ts index 8ed9cf697..3664d375f 100644 --- a/packages/webpack-plugin/src/plugin.ts +++ b/packages/webpack-plugin/src/plugin.ts @@ -49,7 +49,7 @@ import type { import { parse } from 'postcss'; import { getWebpackEntities, StylableWebpackEntities } from './webpack-entities'; import { resolveConfig as resolveStcConfig, STCBuilder } from '@stylable/cli'; -import { createLegacyResolver } from './legacy-module-resolver'; +import { createWebpackResolver } from './legacy-module-resolver'; type OptimizeOptions = OptimizeConfig & { minify?: boolean; @@ -370,7 +370,7 @@ export class StylableWebpackPlugin { const stylableConfig = this.getStylableConfig(compiler)?.config; validateDefaultConfig(stylableConfig?.defaultConfig); - const resolveModule = createLegacyResolver(topLevelFs, { + const resolveModule = createWebpackResolver(topLevelFs, { ...resolverOptions, extensions: [], // use Stylable's default extensions }); diff --git a/packages/webpack-plugin/test/e2e/projects/native-css/webpack.config.js b/packages/webpack-plugin/test/e2e/projects/native-css/webpack.config.js index c37dbf04d..03b08ac7a 100644 --- a/packages/webpack-plugin/test/e2e/projects/native-css/webpack.config.js +++ b/packages/webpack-plugin/test/e2e/projects/native-css/webpack.config.js @@ -1,4 +1,4 @@ -const { StylableWebpackPlugin, createLegacyResolver } = require('@stylable/webpack-plugin'); +const { StylableWebpackPlugin, createWebpackResolver } = require('@stylable/webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); /** @type {import('webpack').Configuration} */ @@ -12,7 +12,7 @@ module.exports = { stylableConfig(config, compiler) { // set custom resolve for test - const resolve = createLegacyResolver(compiler.inputFileSystem, {}); + const resolve = createWebpackResolver(compiler.inputFileSystem, {}); config.resolveModule = (path, request) => { if (request === './resolve-me') { return resolve(path, './custom-resolved.css'); diff --git a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/stylable.config.js b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/stylable.config.js index d0f0dad3d..b33838fce 100644 --- a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/stylable.config.js +++ b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/stylable.config.js @@ -1,11 +1,11 @@ //@ts-check const { join } = require('path'); -const { createLegacyResolver } = require('@stylable/webpack-plugin'); +const { createWebpackResolver } = require('@stylable/webpack-plugin'); module.exports = { defaultConfig(fs) { return { - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { alias: { 'wp-alias': join(__dirname, 'src/wrong'), }, diff --git a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/webpack.config.js b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/webpack.config.js index ac264d0cb..cc58b9059 100644 --- a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/webpack.config.js +++ b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-inline-override/webpack.config.js @@ -1,7 +1,7 @@ const { StylableWebpackPlugin } = require('@stylable/webpack-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); const { join } = require('path'); -const { createLegacyResolver } = require('@stylable/webpack-plugin'); +const { createWebpackResolver } = require('@stylable/webpack-plugin'); /** @type {import('webpack').Configuration} */ module.exports = { @@ -12,7 +12,7 @@ module.exports = { new StylableWebpackPlugin({ stylableConfig: (config) => ({ ...config, - resolveModule: createLegacyResolver(config.fileSystem, { + resolveModule: createWebpackResolver(config.fileSystem, { alias: { 'wp-alias': join(__dirname, 'src/webpack-alias'), }, diff --git a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-override/stylable.config.js b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-override/stylable.config.js index 556d82d00..6827a8018 100644 --- a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-override/stylable.config.js +++ b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver-override/stylable.config.js @@ -1,11 +1,11 @@ //@ts-check const { join } = require('path'); -const { createLegacyResolver } = require('@stylable/webpack-plugin'); +const { createWebpackResolver } = require('@stylable/webpack-plugin'); module.exports = { defaultConfig(fs) { return { - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { alias: { 'wp-alias': join(__dirname, 'src/wrong'), }, @@ -18,7 +18,7 @@ module.exports = { stylableConfig(defaultStylableConfig) { return { ...defaultStylableConfig, - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { alias: { 'wp-alias': join(__dirname, 'src/webpack-alias'), }, diff --git a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver/stylable.config.js b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver/stylable.config.js index 1b1773a3d..5387f2cad 100644 --- a/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver/stylable.config.js +++ b/packages/webpack-plugin/test/e2e/projects/stylable-config-resolver/stylable.config.js @@ -1,12 +1,12 @@ //@ts-check const { join } = require('path'); -const { createLegacyResolver } = require('@stylable/webpack-plugin'); +const { createWebpackResolver } = require('@stylable/webpack-plugin'); const { TsconfigPathsPlugin } = require('tsconfig-paths-webpack-plugin'); module.exports = { defaultConfig(fs) { return { - resolveModule: createLegacyResolver(fs, { + resolveModule: createWebpackResolver(fs, { alias: { 'wp-alias': join(__dirname, 'src/webpack-alias'), },