@ms-cloudpack/bundler-rollup 0.1.1

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/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # @ms-cloudpack/bundler-rollup
2
+
3
+ Provides a Cloudpack bundler abstraction around the Rollup bundler.
4
+
5
+ ## Usage
6
+
7
+ ### `async function bundlePackage(options)`
8
+
9
+ ```tsx
10
+ import { bundlePackage } from '@ms-cloudpack/bundler';
11
+
12
+ async function start() {
13
+ const result = await bundlePackage({
14
+ packagePath: process.cwd(),
15
+ outputPath: path.join(process.cwd(), 'dist'),
16
+ outputType: 'library',
17
+ });
18
+
19
+ console.log(result);
20
+ }
21
+
22
+ start();
23
+ ```
@@ -0,0 +1,15 @@
1
+ import type { BundleOptions } from '@ms-cloudpack/common-types';
2
+ import type { WriteESMStubsResult } from '@ms-cloudpack/esm-stub-utilities';
3
+ import type { OutputOptions, RollupLog, RollupOptions } from 'rollup';
4
+ /**
5
+ * Converts BundlerOptions to Rollup-specific options.
6
+ */
7
+ export declare function getRollupOptions(params: {
8
+ options: Omit<BundleOptions, 'entries'>;
9
+ } & Pick<WriteESMStubsResult, 'newEntries'>): Promise<{
10
+ inputOptions: RollupOptions;
11
+ outputOptions: OutputOptions;
12
+ /** Warnings will be pushed to this array (rollup handles warnings with a callback) */
13
+ warnings: RollupLog[];
14
+ }>;
15
+ //# sourceMappingURL=getRollupOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRollupOptions.d.ts","sourceRoot":"","sources":["../src/getRollupOptions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAI5E,OAAO,KAAK,EAAgB,aAAa,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAUpF;;GAEG;AACH,wBAAsB,gBAAgB,CACpC,MAAM,EAAE;IACN,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,CAAC,CAAC;CACzC,GAAG,IAAI,CAAC,mBAAmB,EAAE,YAAY,CAAC,GAC1C,OAAO,CAAC;IACT,YAAY,EAAE,aAAa,CAAC;IAC5B,aAAa,EAAE,aAAa,CAAC;IAC7B,sFAAsF;IACtF,QAAQ,EAAE,SAAS,EAAE,CAAC;CACvB,CAAC,CAsCD"}
@@ -0,0 +1,51 @@
1
+ import { shouldExternalizePackage } from '@ms-cloudpack/bundler-utilities';
2
+ import { isExternalPackage } from '@ms-cloudpack/package-utilities';
3
+ import fs from 'fs';
4
+ import path from 'path';
5
+ import { getRollupPlugins } from './getRollupPlugins.js';
6
+ // These are the polyfills that we support from the 'rollup-plugin-polyfill-node' plugin
7
+ // that are not included in the node builtins list.
8
+ const polyfills = new Set(['global', '_inherits', '_buffer_list']);
9
+ // Spammy, usually non-actionable warning
10
+ const ignoredWarnings = ['Circular dependency:'];
11
+ /**
12
+ * Converts BundlerOptions to Rollup-specific options.
13
+ */
14
+ export async function getRollupOptions(params) {
15
+ const { options, newEntries } = params;
16
+ const { inputPath, minify, external = [], inlined = [], bundlerOptions = {}, dynamicImports, sourcemap } = options;
17
+ const isExternal = isExternalPackage(inputPath);
18
+ const enableTypescript = !isExternal && fs.existsSync(path.resolve(inputPath, 'tsconfig.json'));
19
+ const warnings = [];
20
+ return {
21
+ warnings,
22
+ inputOptions: {
23
+ external: (id) => shouldExternalizePackage({ id, inlined, external, polyfills, shouldInlineNodeBuiltins: true }),
24
+ ...bundlerOptions.inputOptions,
25
+ // Don't allow overriding the options below
26
+ // Rollup requires entry keys without a leading ./
27
+ input: Object.fromEntries(Object.entries(newEntries).map(([key, value]) => [key.replace(/^\.\//, ''), value])),
28
+ // These are not possible to override properly via JSON config
29
+ plugins: await getRollupPlugins({
30
+ isProduction: minify,
31
+ packagePath: inputPath,
32
+ enableTypescript,
33
+ dynamicImports,
34
+ sourcemap,
35
+ }),
36
+ onwarn: (warning) => {
37
+ if (!ignoredWarnings.some((ignored) => warning.message.includes(ignored))) {
38
+ warnings.push(warning);
39
+ }
40
+ },
41
+ },
42
+ outputOptions: {
43
+ sourcemap,
44
+ ...bundlerOptions.outputOptions,
45
+ // No overriding these options
46
+ dir: options.outputPath ? path.resolve(inputPath, options.outputPath) : inputPath,
47
+ format: 'es',
48
+ },
49
+ };
50
+ }
51
+ //# sourceMappingURL=getRollupOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRollupOptions.js","sourceRoot":"","sources":["../src/getRollupOptions.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,iCAAiC,CAAC;AAG3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,wFAAwF;AACxF,mDAAmD;AACnD,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,CAAC,QAAQ,EAAE,WAAW,EAAE,cAAc,CAAC,CAAC,CAAC;AAEnE,yCAAyC;AACzC,MAAM,eAAe,GAAG,CAAC,sBAAsB,CAAC,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAE2C;IAO3C,MAAM,EAAE,OAAO,EAAE,UAAU,EAAE,GAAG,MAAM,CAAC;IACvC,MAAM,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,GAAG,EAAE,EAAE,OAAO,GAAG,EAAE,EAAE,cAAc,GAAG,EAAE,EAAE,cAAc,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACnH,MAAM,UAAU,GAAG,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAChD,MAAM,gBAAgB,GAAG,CAAC,UAAU,IAAI,EAAE,CAAC,UAAU,CAAC,IA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AAE,IAAI;SACb;KACF,CAAC;AACJ,CAAC","sourcesContent":["import { shouldExternalizePackage } from '@ms-cloudpack/bundler-utilities';\nimport type { BundleOptions } from '@ms-cloudpack/common-types';\nimport type { WriteESMStubsResult } from '@ms-cloudpack/esm-stub-utilities';\nimport { isExternalPackage } from '@ms-cloudpack/package-utilities';\nimport fs from 'fs';\nimport path from 'path';\nimport type { InputOptions, OutputOptions, RollupLog, RollupOptions } from 'rollup';\nimport { getRollupPlugins } from './getRollupPlugins.js';\n\n// These are the polyfills that we support from the 'rollup-plugin-polyfill-node' plugin\n// that are not included in the node builtins list.\nconst polyfills = new Set(['global', '_inherits', '_buffer_list']);\n\n// Spammy, usually non-actionable warning\nconst ignoredWarnings = ['Circular dependency:'];\n\n/**\n * Converts BundlerOptions to Rollup-specific options.\n */\nexport async function getRollupOptions(\n params: {\n options: Omit<BundleOptions, 'entries'>;\n } & Pick<WriteESMStubsResult, 'newEntries'>,\n): Promise<{\n inputOptions: RollupOptions;\n outputOptions: OutputOptions;\n /** Warnings will be pushed to this array (rollup handles warnings with a callback) */\n warnings: RollupLog[];\n}> {\n const { options, newEntries } = params;\n const { inputPath, minify, external = [], inlined = [], bundlerOptions = {}, dynamicImports, sourcemap } = options;\n const isExternal = isExternalPackage(inputPath);\n const enableTypescript = !isExternal && fs.existsSync(path.resolve(inputPath, 'tsconfig.json'));\n const warnings: RollupLog[] = [];\n\n return {\n warnings,\n inputOptions: {\n external: (id) => shouldExternalizePackage({ id, inlined, external, polyfills, shouldInlineNodeBuiltins: true }),\n ...(bundlerOptions.inputOptions as InputOptions),\n // Don't allow overriding the options below\n\n // Rollup requires entry keys without a leading ./\n input: Object.fromEntries(Object.entries(newEntries).map(([key, value]) => [key.replace(/^\\.\\//, ''), value])),\n // These are not possible to override properly via JSON config\n plugins: await getRollupPlugins({\n isProduction: minify,\n packagePath: inputPath,\n enableTypescript,\n dynamicImports,\n sourcemap,\n }),\n onwarn: (warning) => {\n if (!ignoredWarnings.some((ignored) => warning.message.includes(ignored))) {\n warnings.push(warning);\n }\n },\n },\n outputOptions: {\n sourcemap,\n ...(bundlerOptions.outputOptions as OutputOptions),\n // No overriding these options\n dir: options.outputPath ? path.resolve(inputPath, options.outputPath) : inputPath,\n format: 'es',\n },\n };\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { Plugin } from 'rollup';
2
+ export declare function getRollupPlugins(options: {
3
+ isProduction?: boolean;
4
+ packagePath: string;
5
+ enableTypescript?: boolean;
6
+ dynamicImports?: string[];
7
+ sourcemap: boolean | undefined;
8
+ }): Promise<Plugin[]>;
9
+ //# sourceMappingURL=getRollupPlugins.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRollupPlugins.d.ts","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAsBrC,wBAAsB,gBAAgB,CAAC,OAAO,EAAE;IAC9C,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,SAAS,EAAE,OAAO,GAAG,SAAS,CAAC;CAChC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,CAqEpB"}
@@ -0,0 +1,83 @@
1
+ import { getSwcConfig } from '@ms-cloudpack/bundler-utilities';
2
+ import _dynamicImportVariables from '@rollup/plugin-dynamic-import-vars';
3
+ import _image from '@rollup/plugin-image';
4
+ import _json from '@rollup/plugin-json';
5
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
6
+ import _replace from '@rollup/plugin-replace';
7
+ import _terser from '@rollup/plugin-terser';
8
+ import _nodePolyfills from 'rollup-plugin-polyfill-node';
9
+ import _postcss from 'rollup-plugin-postcss';
10
+ import commonjs from './plugins/commonjs/index.js';
11
+ import { normalizeRequireStatements } from './plugins/normalizeRequireStatements.js';
12
+ // Workaround for https://github.com/microsoft/TypeScript/issues/49189#issuecomment-1137756847
13
+ // (https://arethetypeswrong.github.io/?p=%40rollup%2Fplugin-replace%405.0.2)
14
+ // At runtime, we should always be using the ESM version of these packages, which use `export default`.
15
+ // However, typescript interprets the types as CJS modules with a `default` property (which will fail at runtime).
16
+ const json = _json;
17
+ const replace = _replace;
18
+ const terser = _terser;
19
+ const nodePolyfills = _nodePolyfills;
20
+ const postcss = _postcss;
21
+ const image = _image;
22
+ const dynamicImportVariables = _dynamicImportVariables;
23
+ function getSwcPlugin() {
24
+ return import('@rollup/plugin-swc').then((m) => m.default);
25
+ }
26
+ export async function getRollupPlugins(options) {
27
+ const { isProduction, packagePath, enableTypescript, dynamicImports = [], sourcemap } = options;
28
+ return [
29
+ // Used to replaces constants in the code.
30
+ replace({
31
+ values: {
32
+ 'process.env.NODE_ENV': isProduction ? `"production"` : `"development"`,
33
+ DEPRECATED_UNIT_TEST: 'true',
34
+ },
35
+ preventAssignment: true,
36
+ }),
37
+ normalizeRequireStatements(),
38
+ postcss({
39
+ modules: {
40
+ globalModulePaths: [/global\.css$/],
41
+ },
42
+ }),
43
+ // Used to parse commonjs.
44
+ commonjs({
45
+ // Treat all dependencies as external esm modules (since we'll be bundling them.)
46
+ esmExternals: true,
47
+ // When __esModule is true, the default export is `exports.default`; otherwise it's `module.exports`.
48
+ defaultIsModuleExports: true,
49
+ // Convert `require('library')` to `import * as library from 'library'` always, because `import library from
50
+ // 'library' risks runtime failure if the dependency is ESM that doesn't export a default.
51
+ requireReturnsDefault: false,
52
+ }),
53
+ // Used to compile json files into javascript exports.
54
+ json(),
55
+ // // Used to resolve node_modules.
56
+ nodeResolve({
57
+ preferBuiltins: false,
58
+ browser: true,
59
+ extensions: ['.js', '.json', ...(enableTypescript ? ['.ts', '.tsx'] : [])],
60
+ }),
61
+ // Used to browserify node globals (process, global, etc.)
62
+ nodePolyfills(),
63
+ image(),
64
+ enableTypescript &&
65
+ (await getSwcPlugin())({
66
+ swc: getSwcConfig({ packagePath, sourcemap }).ts,
67
+ }),
68
+ // Only run this plugin on **/*.dynamic.* files (plus others as specified) to avoid an extra
69
+ // parsing/processing step on all files.
70
+ // Must be done AFTER the TS step because it can only handle JS syntax.
71
+ dynamicImportVariables({
72
+ include: [
73
+ '**/*.dynamic.*',
74
+ // Convert the dynamic imports options to globs starting with **
75
+ // (the plugin seems to be matching against full paths)
76
+ ...dynamicImports.map((d) => (d.startsWith('**/') ? d : d.replace(/^(\.?\/)?/, '**/'))),
77
+ ],
78
+ }),
79
+ // Minify production builds as a last step.
80
+ !!isProduction && terser(),
81
+ ].filter((plugin) => !!plugin);
82
+ }
83
+ //# sourceMappingURL=getRollupPlugins.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getRollupPlugins.js","sourceRoot":"","sources":["../src/getRollupPlugins.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,uBAAuB,MAAM,oCAAoC,CAAC;AACzE,OAAO,MAAM,MAAM,sBAAsB,CAAC;AAC1C,OAAO,KAAK,MAAM,qBAAqB,CAAC;AACxC,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,QAAQ,MAAM,wBAAwB,CAAC;AAE9C,OAAO,OAAO,MAAM,uBAAuB,CAAC;AAE5C,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,QAAQ,MAAM,6BAA6B,CAAC;AACnD,OAAO,EAAE,0BAA0B,EAAE,MAAM,yCAAyC,CAAC;AAErF,8FAA8F;AAC9F,6EAA6E;AAC7E,uGAAuG;AACvG,kHAAkH;AAClH,MAAM,IAAI,GAAG,KAAwC,CAAC;AACtD,MAAM,OAAO,GAAG,QAA8C,CAAC;AAC/D,MAAM,MAAM,GAAG,OAA4C,CAAC;AAC5D,MAAM,aAAa,GAAG,cAA0D,CAAC;AAC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Aa,EAAE;QAEf,KAAK,EAAE;QAEP,gBAAgB;YACd,CAAC,MAAM,YAAY,EAAE,CAAC,CAAC;gBACrB,GAAG,EAAE,YAAY,CAAC,EAAE,WAAW,EAAE,SAAS,EAAE,CAAC,CAAC,EAAE;aACjD,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;KAC3B,CAAC,MAAM,CAAC,CAAC,MAAM,EAAoB,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AACnD,CAAC","sourcesContent":["import { getSwcConfig } from '@ms-cloudpack/bundler-utilities';\nimport _dynamicImportVariables from '@rollup/plugin-dynamic-import-vars';\nimport _image from '@rollup/plugin-image';\nimport _json from '@rollup/plugin-json';\nimport { nodeResolve } from '@rollup/plugin-node-resolve';\nimport _replace from '@rollup/plugin-replace';\nimport type _swc from '@rollup/plugin-swc';\nimport _terser from '@rollup/plugin-terser';\nimport type { Plugin } from 'rollup';\nimport _nodePolyfills from 'rollup-plugin-polyfill-node';\nimport _postcss from 'rollup-plugin-postcss';\nimport commonjs from './plugins/commonjs/index.js';\nimport { normalizeRequireStatements } from './plugins/normalizeRequireStatements.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 json = _json as unknown as typeof _json.default;\nconst replace = _replace as unknown as typeof _replace.default;\nconst terser = _terser as unknown as typeof _terser.default;\nconst nodePolyfills = _nodePolyfills as unknown as typeof _nodePolyfills.default;\nconst postcss = _postcss as unknown as typeof _postcss.default;\nconst image = _image as unknown as typeof _image.default;\nconst dynamicImportVariables = _dynamicImportVariables as unknown as typeof _dynamicImportVariables.default;\n\nfunction getSwcPlugin() {\n return import('@rollup/plugin-swc').then((m) => m.default) as Promise<typeof _swc.default>;\n}\n\nexport async function getRollupPlugins(options: {\n isProduction?: boolean;\n packagePath: string;\n enableTypescript?: boolean;\n dynamicImports?: string[];\n sourcemap: boolean | undefined;\n}): Promise<Plugin[]> {\n const { isProduction, packagePath, enableTypescript, dynamicImports = [], sourcemap } = options;\n\n return [\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 modules: {\n globalModulePaths: [/global\\.css$/],\n },\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\n // // Used to resolve node_modules.\n nodeResolve({\n preferBuiltins: false,\n browser: true,\n extensions: ['.js', '.json', ...(enableTypescript ? ['.ts', '.tsx'] : [])],\n }),\n\n // Used to browserify node globals (process, global, etc.)\n nodePolyfills(),\n\n image(),\n\n enableTypescript &&\n (await getSwcPlugin())({\n swc: getSwcConfig({ packagePath, sourcemap }).ts,\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 ].filter((plugin): plugin is Plugin => !!plugin);\n}\n"]}
package/lib/index.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ export { rollup as default } from './rollup.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { rollup as default } from './rollup.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { rollup as default } from './rollup.js';\n"]}
@@ -0,0 +1,8 @@
1
+ import type { BundleMessageLocation } from '@ms-cloudpack/common-types';
2
+ import type { RollupLog } from 'rollup';
3
+ export declare function normalizeRollupLoc(params: {
4
+ loc: RollupLog['loc'];
5
+ inputPath: string;
6
+ id?: string;
7
+ }): BundleMessageLocation | undefined;
8
+ //# sourceMappingURL=normalizeRollupLoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeRollupLoc.d.ts","sourceRoot":"","sources":["../src/normalizeRollupLoc.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAExC,wBAAgB,kBAAkB,CAAC,MAAM,EAAE;IACzC,GAAG,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,GAAG,qBAAqB,GAAG,SAAS,CAgBpC"}
@@ -0,0 +1,17 @@
1
+ import { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';
2
+ export function normalizeRollupLoc(params) {
3
+ const { loc, inputPath, id } = params;
4
+ const file = loc?.file || id;
5
+ if (!file) {
6
+ return undefined;
7
+ }
8
+ const location = {
9
+ file: normalizedPathRelativeTo(inputPath, file),
10
+ };
11
+ if (loc) {
12
+ location.line = loc.line;
13
+ location.column = loc.column;
14
+ }
15
+ return location;
16
+ }
17
+ //# sourceMappingURL=normalizeRollupLoc.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeRollupLoc.js","sourceRoot":"","sources":["../src/normalizeRollupLoc.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,wBAAwB,EAAE,MAAM,8BAA8B,CAAC;AAGxE,MAAM,UAAU,kBAAkB,CAAC,MAIlC;IACC,MAAM,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,EAAE,GAAG,MAAM,CAAC;IACtC,MAAM,IAAI,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,QAAQ,GAA0B;QACtC,IAAI,EAAE,wBAAwB,CAAC,SAAS,EAAE,IAAI,CAAC;KAChD,CAAC;IACF,IAAI,GAAG,EAAE,CAAC;QACR,QAAQ,CAAC,IAAI,GAAG,GAAG,CAAC,IAAI,CAAC;QACzB,QAAQ,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC/B,CAAC;IAED,OAAO,QAAQ,CAAC;AAClB,CAAC","sourcesContent":["import type { BundleMessageLocation } from '@ms-cloudpack/common-types';\nimport { normalizedPathRelativeTo } from '@ms-cloudpack/path-utilities';\nimport type { RollupLog } from 'rollup';\n\nexport function normalizeRollupLoc(params: {\n loc: RollupLog['loc'];\n inputPath: string;\n id?: string;\n}): BundleMessageLocation | undefined {\n const { loc, inputPath, id } = params;\n const file = loc?.file || id;\n if (!file) {\n return undefined;\n }\n\n const location: BundleMessageLocation = {\n file: normalizedPathRelativeTo(inputPath, file),\n };\n if (loc) {\n location.line = loc.line;\n location.column = loc.column;\n }\n\n return location;\n}\n"]}
@@ -0,0 +1,13 @@
1
+ import type { BundleOptions, BundlerResult } from '@ms-cloudpack/common-types';
2
+ import type { OutputOptions, RollupOptions, RollupOutput, RollupWarning } from 'rollup';
3
+ /**
4
+ * Converts rollup output to a BundlerResult.
5
+ */
6
+ export declare function normalizeRollupOutput(params: {
7
+ options: Pick<BundleOptions, 'entries' | 'inputPath'>;
8
+ inputOptions: RollupOptions;
9
+ outputOptions: OutputOptions;
10
+ output: RollupOutput;
11
+ warnings: RollupWarning[];
12
+ }): BundlerResult;
13
+ //# sourceMappingURL=normalizeRollupOutput.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeRollupOutput.d.ts","sourceRoot":"","sources":["../src/normalizeRollupOutput.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAoB,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAEjG,OAAO,KAAK,EAAe,aAAa,EAAE,aAAa,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAGrG;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE;IAC5C,OAAO,EAAE,IAAI,CAAC,aAAa,EAAE,SAAS,GAAG,WAAW,CAAC,CAAC;IACtD,YAAY,EAAE,aAAa,CAAC;IAC5B,aAAa,EAAE,aAAa,CAAC;IAC7B,MAAM,EAAE,YAAY,CAAC;IACrB,QAAQ,EAAE,aAAa,EAAE,CAAC;CAC3B,GAAG,aAAa,CAmChB"}
@@ -0,0 +1,38 @@
1
+ import { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';
2
+ import { normalizeRollupLoc } from './normalizeRollupLoc.js';
3
+ /**
4
+ * Converts rollup output to a BundlerResult.
5
+ */
6
+ export function normalizeRollupOutput(params) {
7
+ const { options, inputOptions, outputOptions, output, warnings } = params;
8
+ const outputPath = outputOptions.dir;
9
+ if (!outputPath) {
10
+ throw new Error('Expected outputOptions.dir to be set (this is a bug in Cloudpack)');
11
+ }
12
+ return {
13
+ outputPath,
14
+ outputFiles: output.output?.map((chunk) => {
15
+ const outFile = {
16
+ outputPath: normalizeRelativePath(chunk.fileName),
17
+ exports: chunk.exports,
18
+ };
19
+ // Rollup doesn't include entry point info in the output, so add manually if applicable
20
+ if (outFile.outputPath.endsWith('.js')) {
21
+ const entryPoint = options.entries[outFile.outputPath.replace(/\.js$/, '')];
22
+ if (entryPoint) {
23
+ outFile.entryPoint = entryPoint;
24
+ }
25
+ }
26
+ return outFile;
27
+ }) || [],
28
+ errors: [],
29
+ warnings: warnings.map((warning) => ({
30
+ text: warning.message,
31
+ location: normalizeRollupLoc({ loc: warning.loc, inputPath: options.inputPath }),
32
+ source: 'rollup',
33
+ })),
34
+ rawInput: { inputOptions, outputOptions },
35
+ rawOutput: output,
36
+ };
37
+ }
38
+ //# sourceMappingURL=normalizeRollupOutput.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeRollupOutput.js","sourceRoot":"","sources":["../src/normalizeRollupOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAE1E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAMrC;IACC,MAAM,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,CAAC;IAC1E,MAAM,UAAU,GAAG,aAAa,CAAC,GAAG,CAAC;IACrC,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;IACvF,CAAC;IAED,OAAO;QACL,UAAU;QACV,WAAW,EACT,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,KAAK,EAAoB,EAAE;YAC7C,MAAM,OAAO,GAAqB;gBAChC,UAAU,EAAE,qBAAqB,CAAC,KAAK,CAAC,QAAQ,CAAC;gBACjD,OAAO,EAAG,KAAqB,CAAC,OAAO;aACxC,CAAC;YAEF,uFAAuF;YACvF,IAAI,OAAO,CAAC,UAAU,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,CAAC;gBACvC,MAAM,UAAU,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC;gBAC5E,IAAI,UAAU,EAAE,CAAC;oBACf,OAAO,CAAC,UAAU,GAAG,UAAU,CAAC;gBAClC,CAAC;YACH,CAAC;YAED,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,IAAI,EAAE;QACV,MAAM,EAAE,EAAE;QACV,QAAQ,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;YACnC,IAAI,EAAE,OAAO,CAAC,OAAO;YACrB,QAAQ,EAAE,kBAAkB,CAAC,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,CAAC,SAAS,EAAE,CAAC;YAChF,MAAM,EAAE,QAAQ;SACjB,CAAC,CAAC;QACH,QAAQ,EAAE,EAAE,YAAY,EAAE,aAAa,EAAE;QACzC,SAAS,EAAE,MAA4C;KACxD,CAAC;AACJ,CAAC","sourcesContent":["import type { BundleOptions, BundleOutputFile, BundlerResult } from '@ms-cloudpack/common-types';\nimport { normalizeRelativePath } from '@ms-cloudpack/path-string-parsing';\nimport type { OutputChunk, OutputOptions, RollupOptions, RollupOutput, RollupWarning } from 'rollup';\nimport { normalizeRollupLoc } from './normalizeRollupLoc.js';\n\n/**\n * Converts rollup output to a BundlerResult.\n */\nexport function normalizeRollupOutput(params: {\n options: Pick<BundleOptions, 'entries' | 'inputPath'>;\n inputOptions: RollupOptions;\n outputOptions: OutputOptions;\n output: RollupOutput;\n warnings: RollupWarning[];\n}): BundlerResult {\n const { options, inputOptions, outputOptions, output, warnings } = params;\n const outputPath = outputOptions.dir;\n if (!outputPath) {\n throw new Error('Expected outputOptions.dir to be set (this is a bug in Cloudpack)');\n }\n\n return {\n outputPath,\n outputFiles:\n output.output?.map((chunk): BundleOutputFile => {\n const outFile: BundleOutputFile = {\n outputPath: normalizeRelativePath(chunk.fileName),\n exports: (chunk as OutputChunk).exports,\n };\n\n // Rollup doesn't include entry point info in the output, so add manually if applicable\n if (outFile.outputPath.endsWith('.js')) {\n const entryPoint = options.entries[outFile.outputPath.replace(/\\.js$/, '')];\n if (entryPoint) {\n outFile.entryPoint = entryPoint;\n }\n }\n\n return outFile;\n }) || [],\n errors: [],\n warnings: warnings.map((warning) => ({\n text: warning.message,\n location: normalizeRollupLoc({ loc: warning.loc, inputPath: options.inputPath }),\n source: 'rollup',\n })),\n rawInput: { inputOptions, outputOptions },\n rawOutput: output as unknown as Record<string, unknown>,\n };\n}\n"]}
@@ -0,0 +1,14 @@
1
+ export { commonjs as default };
2
+ declare function commonjs(options?: {}): {
3
+ name: string;
4
+ version: string;
5
+ options(rawOptions: any): any;
6
+ buildStart({ plugins }: {
7
+ plugins: any;
8
+ }): void;
9
+ buildEnd(): void;
10
+ load(id: any): any;
11
+ shouldTransformCachedModule(...args: any[]): any;
12
+ transform(code: any, id: any): any;
13
+ };
14
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/plugins/commonjs/index.js"],"names":[],"mappings":";AA05DA;;;;;;;;;;;EAsQC"}