@ms-cloudpack/bundler-rollup 0.6.21 → 0.6.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/getRollupPlugins.d.ts.map +1 -1
- package/lib/getRollupPlugins.js +1 -2
- package/lib/getRollupPlugins.js.map +1 -1
- package/lib/plugins/postcss/postcss-loader.js +9 -1
- package/lib/plugins/postcss/postcss-loader.js.map +1 -1
- package/lib/plugins/postcss/utils/load-module.js +10 -2
- package/lib/plugins/postcss/utils/load-module.js.map +1 -1
- package/package.json +10 -10
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRollupPlugins.d.ts","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAsC,MAAM,4BAA4B,CAAC;AAUnH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;
|
|
1
|
+
{"version":3,"file":"getRollupPlugins.d.ts","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,aAAa,EAAsC,MAAM,4BAA4B,CAAC;AAUnH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAkBrC,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,OAAO,EAAE,aAAa,GAAG,MAAM,EAAE,CAoJ1G"}
|
package/lib/getRollupPlugins.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { getSwcConfig, getSwcRelayPluginConfig } from '@ms-cloudpack/bundler-utilities';
|
|
2
2
|
import { isExternalPackage, jsxRegex, typescriptRegex, webExtensions } from '@ms-cloudpack/path-utilities';
|
|
3
|
-
import
|
|
3
|
+
import alias from '@rollup/plugin-alias';
|
|
4
4
|
import _commonjs from '@rollup/plugin-commonjs';
|
|
5
5
|
import _dynamicImportVariables from '@rollup/plugin-dynamic-import-vars';
|
|
6
6
|
import { nodeResolve } from '@rollup/plugin-node-resolve';
|
|
@@ -23,7 +23,6 @@ const commonjs = _commonjs;
|
|
|
23
23
|
const nodePolyfills = _nodePolyfills;
|
|
24
24
|
const dynamicImportVariables = _dynamicImportVariables;
|
|
25
25
|
const swc = _swc;
|
|
26
|
-
const alias = aliasPlugin;
|
|
27
26
|
export function getRollupPlugins(options, context) {
|
|
28
27
|
const { minify: isProduction, inputPath: packagePath, dynamicImports = [], sourcemap, dedupeAliases, bundlerCapabilities = {}, } = options;
|
|
29
28
|
const { relay, 'resolve-web-extensions': resolveWebExtensions } = bundlerCapabilities;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getRollupPlugins.js","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC3G,OAAO,WAAW,MAAM,sBAAsB,CAAC;AAC/C,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,IAAI,MAAM,oBAAoB,CAAC;AACtC,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAC5C,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AACrF,OAAO,OAAO,MAAM,4BAA4B,CAAC;AACjD,OAAO,YAAY,MAAM,2BAA2B,CAAC;A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CAAC,GAAG;aACpB,CAAC;QAEJ,eAAe;QACf,UAAU;YACR,GAAG,CAAC;gBACF,OAAO,EAAE,QAAQ;gBACjB,GAAG,EAAE,UAAU,CAAC,GAAG;aACpB,CAAC;QAEJ,4FAA4F;QAC5F,wCAAwC;QACxC,uEAAuE;QACvE,sBAAsB,CAAC;YACrB,OAAO,EAAE;gBACP,gBAAgB;gBAChB,gEAAgE;gBAChE,uDAAuD;gBACvD,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;aACxF;SACF,CAAC;QAEF,2CAA2C;QAC3C,CAAC,CAAC,YAAY,IAAI,MAAM,EAAE;QAE1B,YAAY,CAAC;YACX,OAAO,EAAE,WAAW;SACrB,CAAC;KACH,CAAC,MAAM,CAAC,CAAC,MAAM,EAAoB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { getSwcConfig, getSwcRelayPluginConfig } from '@ms-cloudpack/bundler-utilities';\nimport type { BundleContext, BundleOptions, InternalBundlerCapabilitiesOptions } from '@ms-cloudpack/common-types';\nimport { isExternalPackage, jsxRegex, typescriptRegex, webExtensions } from '@ms-cloudpack/path-utilities';\nimport aliasPlugin from '@rollup/plugin-alias';\nimport _commonjs from '@rollup/plugin-commonjs';\nimport _dynamicImportVariables from '@rollup/plugin-dynamic-import-vars';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport _replace from '@rollup/plugin-replace';\nimport _swc from '@rollup/plugin-swc';\nimport _terser from '@rollup/plugin-terser';\nimport path from 'path';\nimport type { Plugin } from 'rollup';\nimport _nodePolyfills from 'rollup-plugin-polyfill-node';\nimport json from './plugins/json/index.js';\nimport { normalizeRequireStatements } from './plugins/normalizeRequireStatements.js';\nimport postcss from './plugins/postcss/index.js';\nimport stringImport from './plugins/stringImport.js';\n\n// Workaround for https://github.com/microsoft/TypeScript/issues/49189#issuecomment-1137756847\n// (https://arethetypeswrong.github.io/?p=%40rollup%2Fplugin-replace%405.0.2)\n// At runtime, we should always be using the ESM version of these packages, which use `export default`.\n// However, typescript interprets the types as CJS modules with a `default` property (which will fail at runtime).\nconst replace = _replace as unknown as typeof _replace.default;\nconst terser = _terser as unknown as typeof _terser.default;\nconst commonjs = _commonjs as unknown as typeof _commonjs.default;\nconst nodePolyfills = _nodePolyfills as unknown as typeof _nodePolyfills.default;\nconst dynamicImportVariables = _dynamicImportVariables as unknown as typeof _dynamicImportVariables.default;\nconst swc = _swc as unknown as typeof _swc.default;\nconst alias = aliasPlugin as unknown as typeof aliasPlugin.default;\n\nexport function getRollupPlugins(options: Omit<BundleOptions, 'entries'>, context: BundleContext): Plugin[] {\n const {\n minify: isProduction,\n inputPath: packagePath,\n dynamicImports = [],\n sourcemap,\n dedupeAliases,\n bundlerCapabilities = {},\n } = options;\n const { relay, 'resolve-web-extensions': resolveWebExtensions } =\n bundlerCapabilities as InternalBundlerCapabilitiesOptions;\n const { resolve } = context.config;\n\n const isExternal = isExternalPackage(packagePath);\n\n // Only get the SWC config and transform code if needed\n const swcConfigs = context.requiresTranspile\n ? getSwcConfig({ packagePath, sourcemap, reactRefresh: options.hmr })\n : undefined;\n\n // Add relay plugin to SWC configs if enabled\n if (swcConfigs && relay) {\n const addRelayConfig = getSwcRelayPluginConfig({ options: relay, parentUrl: import.meta.url });\n addRelayConfig(swcConfigs.tsx, 'typescript');\n addRelayConfig(swcConfigs.jsx, 'ecmascript');\n }\n\n return [\n // Dedupe alias plugin to redirect imports to app's version\n dedupeAliases &&\n alias({\n entries: Object.entries(dedupeAliases).map(([find, replacement]) => ({\n find,\n replacement,\n })),\n }),\n\n // Used to replaces constants in the code.\n replace({\n values: {\n 'process.env.NODE_ENV': isProduction ? `\"production\"` : `\"development\"`,\n DEPRECATED_UNIT_TEST: 'true',\n },\n preventAssignment: true,\n }),\n\n normalizeRequireStatements(),\n\n postcss({\n inputCwd: packagePath,\n // In addition to this package context, attempt resolving dependencies from the app path.\n // This could potentially be updated in the future to fully respect `resolve.modules`, but it\n // appears that setting is currently only used for runtime (not build) dependency resolution.\n resolveCwd: context.config.appPath,\n // Use named exports in addition to the default export.\n namedExports: true,\n // Respect the `modules` option regardless of the file extension.\n // Otherwise only *.module.* will be passed through postcss-modules and exports won't work correctly.\n autoModules: false,\n // Options for `postcss-modules` plugin. Note that as of writing, rollup-plugin-postcss\n // uses version 4: https://github.com/madyankin/postcss-modules/tree/v4.3.1\n modules: {\n // Treat .css and .s[ac]ss files as global stylesheets unless they have the `.module` suffix\n globalModulePaths: [/(?<!\\.module)\\.(css|s[ac]ss)$/],\n // Export global classnames in addition to local ones\n exportGlobals: true,\n // Convert non-identifier-friendly class names to exported camelCase identifiers (like css-loader),\n // but keep the original names to use in the default export object too\n localsConvention: 'camelCase',\n },\n // don't load postcss config\n config: false,\n minimize: isProduction,\n sourceMap: sourcemap,\n // Disable this warning from sass for now.\n // TODO: since we forked the plugin, we could fix this if we clarify our required sass version or maybe support both\n use: { sass: { silenceDeprecations: ['legacy-js-api'] } },\n }),\n\n // Used to parse commonjs.\n commonjs({\n // Treat all dependencies as external esm modules (since we'll be bundling them.)\n esmExternals: true,\n\n // When __esModule is true, the default export is `exports.default`; otherwise it's `module.exports`.\n defaultIsModuleExports: true,\n\n // Convert `require('library')` to `import * as library from 'library'` always, because `import library from\n // 'library' risks runtime failure if the dependency is ESM that doesn't export a default.\n requireReturnsDefault: false,\n }),\n\n // Used to compile json files into javascript exports.\n json({\n extensions: ['.json', '.resjson'],\n }),\n\n // // Used to resolve node_modules.\n nodeResolve({\n preferBuiltins: false,\n browser: true,\n // TODO: Align with other bundlers https://github.com/microsoft/cloudpack/issues/2687\n extensions: [\n ...(resolveWebExtensions ? webExtensions.filter((ext) => ext.includes('j')) : []),\n '.js',\n '.json',\n ...(!isExternal && resolveWebExtensions ? webExtensions.filter((ext) => !ext.includes('j')) : []),\n ...(!isExternal ? ['.ts', '.tsx'] : []),\n ],\n moduleDirectories: resolve?.modules?.filter((m) => !path.isAbsolute(m)) ?? ['node_modules'],\n modulePaths: resolve?.modules?.filter((m) => path.isAbsolute(m)) ?? undefined,\n }),\n\n // Used to browserify node globals (process, global, etc.)\n nodePolyfills(),\n\n swcConfigs &&\n swc({\n include: typescriptRegex,\n swc: swcConfigs.tsx,\n }),\n\n // Support .jsx\n swcConfigs &&\n swc({\n include: jsxRegex,\n swc: swcConfigs.jsx,\n }),\n\n // Only run this plugin on **/*.dynamic.* files (plus others as specified) to avoid an extra\n // parsing/processing step on all files.\n // Must be done AFTER the TS step because it can only handle JS syntax.\n dynamicImportVariables({\n include: [\n '**/*.dynamic.*',\n // Convert the dynamic imports options to globs starting with **\n // (the plugin seems to be matching against full paths)\n ...dynamicImports.map((d) => (d.startsWith('**/') ? d : d.replace(/^(\\.?\\/)?/, '**/'))),\n ],\n }),\n\n // Minify production builds as a last step.\n !!isProduction && terser(),\n\n stringImport({\n include: '**/*.glsl',\n }),\n ].filter((plugin): plugin is Plugin => !!plugin);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"getRollupPlugins.js","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAExF,OAAO,EAAE,iBAAiB,EAAE,QAAQ,EAAE,eAAe,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC3G,OAAO,KAAK,MAAM,sBAAsB,CAAC;AACzC,OAAO,SAAS,MAAM,yBAAyB,CAAC;AAChD,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAC9C,OAAO,IAAI,MAAM,o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3F,WAAW,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,IAAI,SAAS;SAC9E,CAAC;QAEF,0DAA0D;QAC1D,aAAa,EAAE;QAEf,UAAU;YACR,GAAG,CAAC;gBACF,OAAO,EAAE,eAAe;gBACxB,GAAG,EAAE,UAAU,CAAC,GAAG;aACpB,CAAC;QAEJ,eAAe;QACf,UAAU;YACR,GAAG,CAAC;gBACF,OAAO,EAAE,QAAQ;gBACjB,GAAG,EAAE,UAAU,CAAC,GAAG;aACpB,CAAC;QAEJ,4FAA4F;QAC5F,wCAAwC;QACxC,uEAAuE;QACvE,sBAAsB,CAAC;YACrB,OAAO,EAAE;gBACP,gBAAgB;gBAChB,gEAAgE;gBAChE,uDAAuD;gBACvD,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC,CAAC;aACxF;SACF,CAAC;QAEF,2CAA2C;QAC3C,CAAC,CAAC,YAAY,IAAI,MAAM,EAAE;QAE1B,YAAY,CAAC;YACX,OAAO,EAAE,WAAW;SACrB,CAAC;KACH,CAAC,MAAM,CAAC,CAAC,MAAM,EAAoB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { getSwcConfig, getSwcRelayPluginConfig } from '@ms-cloudpack/bundler-utilities';\nimport type { BundleContext, BundleOptions, InternalBundlerCapabilitiesOptions } from '@ms-cloudpack/common-types';\nimport { isExternalPackage, jsxRegex, typescriptRegex, webExtensions } from '@ms-cloudpack/path-utilities';\nimport alias from '@rollup/plugin-alias';\nimport _commonjs from '@rollup/plugin-commonjs';\nimport _dynamicImportVariables from '@rollup/plugin-dynamic-import-vars';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport _replace from '@rollup/plugin-replace';\nimport _swc from '@rollup/plugin-swc';\nimport _terser from '@rollup/plugin-terser';\nimport path from 'path';\nimport type { Plugin } from 'rollup';\nimport _nodePolyfills from 'rollup-plugin-polyfill-node';\nimport json from './plugins/json/index.js';\nimport { normalizeRequireStatements } from './plugins/normalizeRequireStatements.js';\nimport postcss from './plugins/postcss/index.js';\nimport stringImport from './plugins/stringImport.js';\n\n// Workaround for https://github.com/microsoft/TypeScript/issues/49189#issuecomment-1137756847\n// (https://arethetypeswrong.github.io/?p=%40rollup%2Fplugin-replace%405.0.2)\n// At runtime, we should always be using the ESM version of these packages, which use `export default`.\n// However, typescript interprets the types as CJS modules with a `default` property (which will fail at runtime).\nconst replace = _replace as unknown as typeof _replace.default;\nconst terser = _terser as unknown as typeof _terser.default;\nconst commonjs = _commonjs as unknown as typeof _commonjs.default;\nconst nodePolyfills = _nodePolyfills as unknown as typeof _nodePolyfills.default;\nconst dynamicImportVariables = _dynamicImportVariables as unknown as typeof _dynamicImportVariables.default;\nconst swc = _swc as unknown as typeof _swc.default;\n\nexport function getRollupPlugins(options: Omit<BundleOptions, 'entries'>, context: BundleContext): Plugin[] {\n const {\n minify: isProduction,\n inputPath: packagePath,\n dynamicImports = [],\n sourcemap,\n dedupeAliases,\n bundlerCapabilities = {},\n } = options;\n const { relay, 'resolve-web-extensions': resolveWebExtensions } =\n bundlerCapabilities as InternalBundlerCapabilitiesOptions;\n const { resolve } = context.config;\n\n const isExternal = isExternalPackage(packagePath);\n\n // Only get the SWC config and transform code if needed\n const swcConfigs = context.requiresTranspile\n ? getSwcConfig({ packagePath, sourcemap, reactRefresh: options.hmr })\n : undefined;\n\n // Add relay plugin to SWC configs if enabled\n if (swcConfigs && relay) {\n const addRelayConfig = getSwcRelayPluginConfig({ options: relay, parentUrl: import.meta.url });\n addRelayConfig(swcConfigs.tsx, 'typescript');\n addRelayConfig(swcConfigs.jsx, 'ecmascript');\n }\n\n return [\n // Dedupe alias plugin to redirect imports to app's version\n dedupeAliases &&\n alias({\n entries: Object.entries(dedupeAliases).map(([find, replacement]) => ({\n find,\n replacement,\n })),\n }),\n\n // Used to replaces constants in the code.\n replace({\n values: {\n 'process.env.NODE_ENV': isProduction ? `\"production\"` : `\"development\"`,\n DEPRECATED_UNIT_TEST: 'true',\n },\n preventAssignment: true,\n }),\n\n normalizeRequireStatements(),\n\n postcss({\n inputCwd: packagePath,\n // In addition to this package context, attempt resolving dependencies from the app path.\n // This could potentially be updated in the future to fully respect `resolve.modules`, but it\n // appears that setting is currently only used for runtime (not build) dependency resolution.\n resolveCwd: context.config.appPath,\n // Use named exports in addition to the default export.\n namedExports: true,\n // Respect the `modules` option regardless of the file extension.\n // Otherwise only *.module.* will be passed through postcss-modules and exports won't work correctly.\n autoModules: false,\n // Options for `postcss-modules` plugin. Note that as of writing, rollup-plugin-postcss\n // uses version 4: https://github.com/madyankin/postcss-modules/tree/v4.3.1\n modules: {\n // Treat .css and .s[ac]ss files as global stylesheets unless they have the `.module` suffix\n globalModulePaths: [/(?<!\\.module)\\.(css|s[ac]ss)$/],\n // Export global classnames in addition to local ones\n exportGlobals: true,\n // Convert non-identifier-friendly class names to exported camelCase identifiers (like css-loader),\n // but keep the original names to use in the default export object too\n localsConvention: 'camelCase',\n },\n // don't load postcss config\n config: false,\n minimize: isProduction,\n sourceMap: sourcemap,\n // Disable this warning from sass for now.\n // TODO: since we forked the plugin, we could fix this if we clarify our required sass version or maybe support both\n use: { sass: { silenceDeprecations: ['legacy-js-api'] } },\n }),\n\n // Used to parse commonjs.\n commonjs({\n // Treat all dependencies as external esm modules (since we'll be bundling them.)\n esmExternals: true,\n\n // When __esModule is true, the default export is `exports.default`; otherwise it's `module.exports`.\n defaultIsModuleExports: true,\n\n // Convert `require('library')` to `import * as library from 'library'` always, because `import library from\n // 'library' risks runtime failure if the dependency is ESM that doesn't export a default.\n requireReturnsDefault: false,\n }),\n\n // Used to compile json files into javascript exports.\n json({\n extensions: ['.json', '.resjson'],\n }),\n\n // // Used to resolve node_modules.\n nodeResolve({\n preferBuiltins: false,\n browser: true,\n // TODO: Align with other bundlers https://github.com/microsoft/cloudpack/issues/2687\n extensions: [\n ...(resolveWebExtensions ? webExtensions.filter((ext) => ext.includes('j')) : []),\n '.js',\n '.json',\n ...(!isExternal && resolveWebExtensions ? webExtensions.filter((ext) => !ext.includes('j')) : []),\n ...(!isExternal ? ['.ts', '.tsx'] : []),\n ],\n moduleDirectories: resolve?.modules?.filter((m) => !path.isAbsolute(m)) ?? ['node_modules'],\n modulePaths: resolve?.modules?.filter((m) => path.isAbsolute(m)) ?? undefined,\n }),\n\n // Used to browserify node globals (process, global, etc.)\n nodePolyfills(),\n\n swcConfigs &&\n swc({\n include: typescriptRegex,\n swc: swcConfigs.tsx,\n }),\n\n // Support .jsx\n swcConfigs &&\n swc({\n include: jsxRegex,\n swc: swcConfigs.jsx,\n }),\n\n // Only run this plugin on **/*.dynamic.* files (plus others as specified) to avoid an extra\n // parsing/processing step on all files.\n // Must be done AFTER the TS step because it can only handle JS syntax.\n dynamicImportVariables({\n include: [\n '**/*.dynamic.*',\n // Convert the dynamic imports options to globs starting with **\n // (the plugin seems to be matching against full paths)\n ...dynamicImports.map((d) => (d.startsWith('**/') ? d : d.replace(/^(\\.?\\/)?/, '**/'))),\n ],\n }),\n\n // Minify production builds as a last step.\n !!isProduction && terser(),\n\n stringImport({\n include: '**/*.glsl',\n }),\n ].filter((plugin): plugin is Plugin => !!plugin);\n}\n"]}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
1
9
|
import { createRequire } from 'module';
|
|
2
10
|
import postcss from 'postcss';
|
|
3
11
|
import { identifier } from 'safe-identifier';
|
|
@@ -27,7 +35,7 @@ async function ensurePostCSSOption(option) {
|
|
|
27
35
|
if (typeof option === 'string') {
|
|
28
36
|
try {
|
|
29
37
|
const resolvedPath = require.resolve(option);
|
|
30
|
-
return (await import(resolvedPath));
|
|
38
|
+
return (await import(__rewriteRelativeImportExtension(resolvedPath)));
|
|
31
39
|
}
|
|
32
40
|
catch {
|
|
33
41
|
return option;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postcss-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAG1D,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC/C,MAAM,eAAe,GAAG,OAAO,CAAC,OAAO,CAAC,mCAAmC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,GAAG,CAAC,CAAC;AAErG,4BAA4B;AAE5B;;GAEG;AACH,SAAS,qBAAqB,CAAC,GAAW;IACxC,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC,KAAK,EAAE,EAAE;QAClC,OAAO,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,GAAG,CAAC;IACzC,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,SAAS,eAAe,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AO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAClF,IAAI,CAAC;QACb,CAAC;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,GAAG,EAAE,SAAS;YACd,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { createRequire } from 'module';\nimport postcss from 'postcss';\nimport { identifier } from 'safe-identifier';\nimport { normalizePath } from './utils/normalize-path.js';\nimport type { ExtractResult, InternalPostCSSLoaderOptions, Loader } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\\\/]+/g, '/');\n\n// loadConfig helper removed\n\n/**\n * Escape CSS class name dashes for JavaScript identifiers\n */\nfunction escapeClassNameDashes(str: string) {\n return str.replace(/-+/g, (match) => {\n return `$${match.replace(/-/g, '_')}$`;\n });\n}\n\n/**\n * Ensure class name is a valid JavaScript identifier\n */\nfunction ensureClassName(name: string): string {\n const escapedName = escapeClassNameDashes(name);\n return identifier(escapedName, false);\n}\n\n/**\n * Ensure PostCSS option is properly loaded\n */\nasync function ensurePostCSSOption<T>(option: unknown): Promise<T | undefined> {\n if (typeof option === 'string') {\n try {\n const resolvedPath = require.resolve(option);\n return (await import(resolvedPath)) as T;\n } catch {\n return option as T;\n }\n }\n return option as T;\n}\n\nfunction isModuleFile(file: string): boolean {\n return /\\.module\\.[a-z]{2,6}$/.test(file);\n}\n\nexport const postcssLoader: Loader<InternalPostCSSLoaderOptions> = {\n name: 'postcss',\n alwaysProcess: true,\n\n async process({ code, map }) {\n // This is modified to not load postcss config.\n if (this.options.config !== false) {\n throw new Error(\n 'This is a fork of rollup-plugin-postcss that does not support loading postcss config. ' +\n 'Please set `config: false` in the plugin options.',\n );\n }\n\n const { options } = this;\n const plugins = [...(options.postcss.plugins || [])];\n const shouldExtract = options.extract;\n const shouldInject = options.inject;\n\n const modulesExported: Record<string, Record<string, string>> = {};\n const autoModules = options.autoModules !== false && options.onlyModules !== true;\n const isAutoModule = autoModules && isModuleFile(this.id);\n const supportModules = autoModules ? isAutoModule : options.modules;\n\n if (supportModules) {\n plugins.unshift(\n (await import('postcss-modules')).default({\n // In tests\n // Skip hash in names since css content on windows and linux would differ because of `new line` (\\r?\\n)\n // eslint-disable-next-line no-restricted-properties\n generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',\n ...options.modules,\n getJSON(filepath, json, outpath) {\n modulesExported[filepath] = json;\n if (typeof options.modules === 'object' && typeof options.modules.getJSON === 'function') {\n return options.modules.getJSON(filepath, json, outpath);\n }\n },\n }),\n );\n }\n\n // If shouldExtract, minimize is done after all CSS are extracted to a file\n if (!shouldExtract && options.minimize) {\n plugins.push((await import('cssnano')).default(options.minimize));\n }\n\n const postcssOptions: postcss.ProcessOptions = {\n // Allow overriding `to` for some plugins that are relying on this value\n to: options.to || this.id,\n from: this.id,\n map: this.sourceMap ? { inline: !shouldExtract, annotation: false } : false,\n parser: await ensurePostCSSOption(options.postcss.parser),\n syntax: await ensurePostCSSOption(options.postcss.syntax),\n stringifier: await ensurePostCSSOption(options.postcss.stringifier),\n // this was spread in before but doesn't appear to exist\n // exec: options.postcss.exec,\n };\n\n if (map && typeof postcssOptions.map === 'object') {\n postcssOptions.map.prev = typeof map === 'string' ? (JSON.parse(map) as object) : map;\n }\n\n if (plugins.length === 0) {\n // Prevent from postcss warning:\n // You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js\n plugins.push({\n postcssPlugin: 'postcss-noop-plugin',\n Once() {},\n });\n }\n\n const result = await postcss(plugins).process(code, postcssOptions);\n\n for (const message of result.messages) {\n if (message.type === 'dependency') {\n this.dependencies.add(message.file as string);\n }\n }\n\n for (const warning of result.warnings()) {\n this.warn({ message: warning.text, ...warning });\n }\n\n const outputMap = result.map && (JSON.parse(result.map.toString()) as ExtractResult['map']);\n if (outputMap && typeof outputMap === 'object' && 'sources' in outputMap) {\n outputMap.sources = outputMap.sources.map((v) => normalizePath(v));\n }\n\n let output = '';\n let extracted: ExtractResult | undefined;\n\n if (options.namedExports) {\n const json = modulesExported[this.id];\n const getClassName = typeof options.namedExports === 'function' ? options.namedExports : ensureClassName;\n\n for (const name in json) {\n const newName = getClassName(name);\n // Log transformed class names\n // But skip this when namedExports is a function\n // Since a user like you can manually log that if you want\n if (name !== newName && typeof options.namedExports !== 'function') {\n // Logging this as an absolute path is better for our use case\n this.warn(`Exported \"${name}\" as \"${newName}\" in ${this.id}`);\n }\n\n if (!json[newName]) {\n json[newName] = json[name];\n }\n\n output += `export var ${newName} = ${JSON.stringify(json[name])};\\n`;\n }\n }\n\n const cssVariableName = identifier('css', true);\n\n if (shouldExtract) {\n output += `export default ${JSON.stringify(modulesExported[this.id])};`;\n extracted = {\n id: this.id,\n code: result.css,\n map: outputMap,\n };\n } else {\n const module = supportModules ? JSON.stringify(modulesExported[this.id]) : cssVariableName;\n output +=\n `var ${cssVariableName} = ${JSON.stringify(result.css)};\\n` +\n `export default ${module};\\n` +\n `export var stylesheet=${JSON.stringify(result.css)};`;\n }\n\n if (!shouldExtract && shouldInject) {\n output +=\n typeof options.inject === 'function'\n ? options.inject(cssVariableName, this.id)\n : `\\nimport styleInject from '${styleInjectPath}';\\n` +\n `styleInject(${cssVariableName}${\n Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''\n });`;\n }\n\n return {\n code: output,\n map: outputMap,\n extracted,\n };\n },\n};\n"]}
|
|
1
|
+
{"version":3,"file":"postcss-loader.js","sourceRoot":"","sources":["../../../src/plugins/postcss/postcss-loader.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,OAAO,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,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AAM,KAAK;oBAC7B,yBAAyB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAC;QAC3D,CAAC;QAED,IAAI,CAAC,aAAa,IAAI,YAAY,EAAE,CAAC;YACnC,MAAM;gBACJ,OAAO,OAAO,CAAC,MAAM,KAAK,UAAU;oBAClC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,eAAe,EAAE,IAAI,CAAC,EAAE,CAAC;oBAC1C,CAAC,CAAC,8BAA8B,eAAe,MAAM;wBACnD,eAAe,eAAe,GAC5B,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAClF,IAAI,CAAC;QACb,CAAC;QAED,OAAO;YACL,IAAI,EAAE,MAAM;YACZ,GAAG,EAAE,SAAS;YACd,SAAS;SACV,CAAC;IACJ,CAAC;CACF,CAAC","sourcesContent":["import { createRequire } from 'module';\nimport postcss from 'postcss';\nimport { identifier } from 'safe-identifier';\nimport { normalizePath } from './utils/normalize-path.js';\nimport type { ExtractResult, InternalPostCSSLoaderOptions, Loader } from './types.js';\n\nconst require = createRequire(import.meta.url);\nconst styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\\\/]+/g, '/');\n\n// loadConfig helper removed\n\n/**\n * Escape CSS class name dashes for JavaScript identifiers\n */\nfunction escapeClassNameDashes(str: string) {\n return str.replace(/-+/g, (match) => {\n return `$${match.replace(/-/g, '_')}$`;\n });\n}\n\n/**\n * Ensure class name is a valid JavaScript identifier\n */\nfunction ensureClassName(name: string): string {\n const escapedName = escapeClassNameDashes(name);\n return identifier(escapedName, false);\n}\n\n/**\n * Ensure PostCSS option is properly loaded\n */\nasync function ensurePostCSSOption<T>(option: unknown): Promise<T | undefined> {\n if (typeof option === 'string') {\n try {\n const resolvedPath = require.resolve(option);\n return (await import(resolvedPath)) as T;\n } catch {\n return option as T;\n }\n }\n return option as T;\n}\n\nfunction isModuleFile(file: string): boolean {\n return /\\.module\\.[a-z]{2,6}$/.test(file);\n}\n\nexport const postcssLoader: Loader<InternalPostCSSLoaderOptions> = {\n name: 'postcss',\n alwaysProcess: true,\n\n async process({ code, map }) {\n // This is modified to not load postcss config.\n if (this.options.config !== false) {\n throw new Error(\n 'This is a fork of rollup-plugin-postcss that does not support loading postcss config. ' +\n 'Please set `config: false` in the plugin options.',\n );\n }\n\n const { options } = this;\n const plugins = [...(options.postcss.plugins || [])];\n const shouldExtract = options.extract;\n const shouldInject = options.inject;\n\n const modulesExported: Record<string, Record<string, string>> = {};\n const autoModules = options.autoModules !== false && options.onlyModules !== true;\n const isAutoModule = autoModules && isModuleFile(this.id);\n const supportModules = autoModules ? isAutoModule : options.modules;\n\n if (supportModules) {\n plugins.unshift(\n (await import('postcss-modules')).default({\n // In tests\n // Skip hash in names since css content on windows and linux would differ because of `new line` (\\r?\\n)\n // eslint-disable-next-line no-restricted-properties\n generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',\n ...options.modules,\n getJSON(filepath, json, outpath) {\n modulesExported[filepath] = json;\n if (typeof options.modules === 'object' && typeof options.modules.getJSON === 'function') {\n return options.modules.getJSON(filepath, json, outpath);\n }\n },\n }),\n );\n }\n\n // If shouldExtract, minimize is done after all CSS are extracted to a file\n if (!shouldExtract && options.minimize) {\n plugins.push((await import('cssnano')).default(options.minimize));\n }\n\n const postcssOptions: postcss.ProcessOptions = {\n // Allow overriding `to` for some plugins that are relying on this value\n to: options.to || this.id,\n from: this.id,\n map: this.sourceMap ? { inline: !shouldExtract, annotation: false } : false,\n parser: await ensurePostCSSOption(options.postcss.parser),\n syntax: await ensurePostCSSOption(options.postcss.syntax),\n stringifier: await ensurePostCSSOption(options.postcss.stringifier),\n // this was spread in before but doesn't appear to exist\n // exec: options.postcss.exec,\n };\n\n if (map && typeof postcssOptions.map === 'object') {\n postcssOptions.map.prev = typeof map === 'string' ? (JSON.parse(map) as object) : map;\n }\n\n if (plugins.length === 0) {\n // Prevent from postcss warning:\n // You did not set any plugins, parser, or stringifier. Right now, PostCSS does nothing. Pick plugins for your case on https://www.postcss.parts/ and use them in postcss.config.js\n plugins.push({\n postcssPlugin: 'postcss-noop-plugin',\n Once() {},\n });\n }\n\n const result = await postcss(plugins).process(code, postcssOptions);\n\n for (const message of result.messages) {\n if (message.type === 'dependency') {\n this.dependencies.add(message.file as string);\n }\n }\n\n for (const warning of result.warnings()) {\n this.warn({ message: warning.text, ...warning });\n }\n\n const outputMap = result.map && (JSON.parse(result.map.toString()) as ExtractResult['map']);\n if (outputMap && typeof outputMap === 'object' && 'sources' in outputMap) {\n outputMap.sources = outputMap.sources.map((v) => normalizePath(v));\n }\n\n let output = '';\n let extracted: ExtractResult | undefined;\n\n if (options.namedExports) {\n const json = modulesExported[this.id];\n const getClassName = typeof options.namedExports === 'function' ? options.namedExports : ensureClassName;\n\n for (const name in json) {\n const newName = getClassName(name);\n // Log transformed class names\n // But skip this when namedExports is a function\n // Since a user like you can manually log that if you want\n if (name !== newName && typeof options.namedExports !== 'function') {\n // Logging this as an absolute path is better for our use case\n this.warn(`Exported \"${name}\" as \"${newName}\" in ${this.id}`);\n }\n\n if (!json[newName]) {\n json[newName] = json[name];\n }\n\n output += `export var ${newName} = ${JSON.stringify(json[name])};\\n`;\n }\n }\n\n const cssVariableName = identifier('css', true);\n\n if (shouldExtract) {\n output += `export default ${JSON.stringify(modulesExported[this.id])};`;\n extracted = {\n id: this.id,\n code: result.css,\n map: outputMap,\n };\n } else {\n const module = supportModules ? JSON.stringify(modulesExported[this.id]) : cssVariableName;\n output +=\n `var ${cssVariableName} = ${JSON.stringify(result.css)};\\n` +\n `export default ${module};\\n` +\n `export var stylesheet=${JSON.stringify(result.css)};`;\n }\n\n if (!shouldExtract && shouldInject) {\n output +=\n typeof options.inject === 'function'\n ? options.inject(cssVariableName, this.id)\n : `\\nimport styleInject from '${styleInjectPath}';\\n` +\n `styleInject(${cssVariableName}${\n Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''\n });`;\n }\n\n return {\n code: output,\n map: outputMap,\n extracted,\n };\n },\n};\n"]}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
var __rewriteRelativeImportExtension = (this && this.__rewriteRelativeImportExtension) || function (path, preserveJsx) {
|
|
2
|
+
if (typeof path === "string" && /^\.\.?\//.test(path)) {
|
|
3
|
+
return path.replace(/\.(tsx)$|((?:\.d)?)((?:\.[^./]+?)?)\.([cm]?)ts$/i, function (m, tsx, d, ext, cm) {
|
|
4
|
+
return tsx ? preserveJsx ? ".jsx" : ".js" : d && (!ext || !cm) ? m : (d + ext + "." + cm.toLowerCase() + "js");
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
return path;
|
|
8
|
+
};
|
|
1
9
|
import { resolveModule } from '@ms-cloudpack/path-utilities';
|
|
2
10
|
/**
|
|
3
11
|
* Load a module using modern ESM dynamic imports. It will try to import from the `bundler-rollup`
|
|
@@ -9,13 +17,13 @@ export async function loadModule(params) {
|
|
|
9
17
|
const { moduleId, cwd } = params;
|
|
10
18
|
try {
|
|
11
19
|
// Try to import the module directly
|
|
12
|
-
return (await import(moduleId));
|
|
20
|
+
return (await import(__rewriteRelativeImportExtension(moduleId)));
|
|
13
21
|
}
|
|
14
22
|
catch {
|
|
15
23
|
// If direct import fails, try resolving from current working directory
|
|
16
24
|
try {
|
|
17
25
|
const resolvedUrl = resolveModule({ importSpecifier: moduleId, parentPath: cwd });
|
|
18
|
-
return (await import(resolvedUrl.toString()));
|
|
26
|
+
return (await import(__rewriteRelativeImportExtension(resolvedUrl.toString())));
|
|
19
27
|
}
|
|
20
28
|
catch {
|
|
21
29
|
// Return null if module cannot be loaded
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"load-module.js","sourceRoot":"","sources":["../../../../src/plugins/postcss/utils/load-module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAU,MAGzC;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,CAAC;QACH,oCAAoC;QACpC,OAAO,CAAC,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"load-module.js","sourceRoot":"","sources":["../../../../src/plugins/postcss/utils/load-module.ts"],"names":[],"mappings":";;;;;;;;AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAE7D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,UAAU,CAAU,MAGzC;IACC,MAAM,EAAE,QAAQ,EAAE,GAAG,EAAE,GAAG,MAAM,CAAC;IAEjC,IAAI,CAAC;QACH,oCAAoC;QACpC,OAAO,CAAC,MAAM,MAAM,kCAAC,QAAQ,EAAC,CAAmC,CAAC;IACpE,CAAC;IAAC,MAAM,CAAC;QACP,uEAAuE;QACvE,IAAI,CAAC;YACH,MAAM,WAAW,GAAG,aAAa,CAAC,EAAE,eAAe,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,EAAE,CAAC,CAAC;YAClF,OAAO,CAAC,MAAM,MAAM,kCAAC,WAAW,CAAC,QAAQ,EAAE,EAAC,CAAmC,CAAC;QAClF,CAAC;QAAC,MAAM,CAAC;YACP,yCAAyC;YACzC,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;AACH,CAAC","sourcesContent":["import { resolveModule } from '@ms-cloudpack/path-utilities';\n\n/**\n * Load a module using modern ESM dynamic imports. It will try to import from the `bundler-rollup`\n * package context first, or fall back to importing from `cwd`.\n * @returns The loaded module, or null if not found. Depending on the module format, the expected\n * contents may be either at the top level or under `default`.\n */\nexport async function loadModule<TModule>(params: {\n moduleId: string;\n cwd: string;\n}): Promise<TModule | { default: TModule } | null> {\n const { moduleId, cwd } = params;\n\n try {\n // Try to import the module directly\n return (await import(moduleId)) as TModule | { default: TModule };\n } catch {\n // If direct import fails, try resolving from current working directory\n try {\n const resolvedUrl = resolveModule({ importSpecifier: moduleId, parentPath: cwd });\n return (await import(resolvedUrl.toString())) as TModule | { default: TModule };\n } catch {\n // Return null if module cannot be loaded\n return null;\n }\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ms-cloudpack/bundler-rollup",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.23",
|
|
4
4
|
"description": "Cloudpack's wrapper for the Rollup bundler",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -25,27 +25,27 @@
|
|
|
25
25
|
"prepack": "cp .npmignore lib/.npmignore"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ms-cloudpack/bundler-capabilities": "^0.5.
|
|
29
|
-
"@ms-cloudpack/bundler-utilities": "^0.9.
|
|
30
|
-
"@ms-cloudpack/common-types": "^0.
|
|
28
|
+
"@ms-cloudpack/bundler-capabilities": "^0.5.3",
|
|
29
|
+
"@ms-cloudpack/bundler-utilities": "^0.9.16",
|
|
30
|
+
"@ms-cloudpack/common-types": "^0.34.0",
|
|
31
31
|
"@ms-cloudpack/common-types-browser": "^0.6.5",
|
|
32
|
-
"@ms-cloudpack/esm-stub-utilities": "^0.16.
|
|
33
|
-
"@ms-cloudpack/package-utilities": "^13.
|
|
32
|
+
"@ms-cloudpack/esm-stub-utilities": "^0.16.2",
|
|
33
|
+
"@ms-cloudpack/package-utilities": "^13.8.0",
|
|
34
34
|
"@ms-cloudpack/path-string-parsing": "^1.3.0",
|
|
35
|
-
"@ms-cloudpack/path-utilities": "^3.2.
|
|
36
|
-
"@rollup/plugin-alias": "^
|
|
35
|
+
"@ms-cloudpack/path-utilities": "^3.2.10",
|
|
36
|
+
"@rollup/plugin-alias": "^6.0.0",
|
|
37
37
|
"@rollup/plugin-commonjs": "^29.0.0",
|
|
38
38
|
"@rollup/plugin-dynamic-import-vars": "^2.0.0",
|
|
39
39
|
"@rollup/plugin-node-resolve": "^16.0.0",
|
|
40
40
|
"@rollup/plugin-replace": "^6.0.0",
|
|
41
41
|
"@rollup/plugin-swc": "^0.4.0",
|
|
42
|
-
"@rollup/plugin-terser": "^0.
|
|
42
|
+
"@rollup/plugin-terser": "^1.0.0",
|
|
43
43
|
"@rollup/plugin-url": "^8.0.0",
|
|
44
44
|
"@rollup/pluginutils": "^5.0.1",
|
|
45
45
|
"@swc/core": "^1.3.0",
|
|
46
46
|
"@swc/plugin-relay": ">= 6.0.0",
|
|
47
47
|
"concat-with-sourcemaps": "^1.1.0",
|
|
48
|
-
"cssnano": "^
|
|
48
|
+
"cssnano": "^7.0.0",
|
|
49
49
|
"magic-string": "^0.30.5",
|
|
50
50
|
"p-queue": "^9.0.0",
|
|
51
51
|
"pify": "^6.0.0",
|