@ms-cloudpack/bundler-rollup 0.6.0 → 0.6.2

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.
Files changed (42) hide show
  1. package/lib/getRollupPlugins.d.ts.map +1 -1
  2. package/lib/getRollupPlugins.js +5 -5
  3. package/lib/getRollupPlugins.js.map +1 -1
  4. package/lib/plugins/postcss/index.d.ts +3 -3
  5. package/lib/plugins/postcss/index.d.ts.map +1 -1
  6. package/lib/plugins/postcss/index.js +8 -520
  7. package/lib/plugins/postcss/index.js.map +1 -1
  8. package/lib/plugins/postcss/less-loader.d.ts +9 -0
  9. package/lib/plugins/postcss/less-loader.d.ts.map +1 -0
  10. package/lib/plugins/postcss/less-loader.js +36 -0
  11. package/lib/plugins/postcss/less-loader.js.map +1 -0
  12. package/lib/plugins/postcss/loaders.d.ts +26 -0
  13. package/lib/plugins/postcss/loaders.d.ts.map +1 -0
  14. package/lib/plugins/postcss/loaders.js +93 -0
  15. package/lib/plugins/postcss/loaders.js.map +1 -0
  16. package/lib/plugins/postcss/postcss-loader.d.ts +10 -0
  17. package/lib/plugins/postcss/postcss-loader.d.ts.map +1 -0
  18. package/lib/plugins/postcss/postcss-loader.js +168 -0
  19. package/lib/plugins/postcss/postcss-loader.js.map +1 -0
  20. package/lib/plugins/postcss/sass-loader.d.ts +9 -0
  21. package/lib/plugins/postcss/sass-loader.d.ts.map +1 -0
  22. package/lib/plugins/postcss/sass-loader.js +99 -0
  23. package/lib/plugins/postcss/sass-loader.js.map +1 -0
  24. package/lib/plugins/postcss/types.d.ts +42 -0
  25. package/lib/plugins/postcss/types.d.ts.map +1 -0
  26. package/lib/plugins/postcss/types.js +3 -0
  27. package/lib/plugins/postcss/types.js.map +1 -0
  28. package/lib/plugins/postcss/utils/humanlize-path.d.ts +3 -0
  29. package/lib/plugins/postcss/utils/humanlize-path.d.ts.map +1 -0
  30. package/lib/plugins/postcss/utils/humanlize-path.js +7 -0
  31. package/lib/plugins/postcss/utils/humanlize-path.js.map +1 -0
  32. package/lib/plugins/postcss/utils/load-module.d.ts +7 -0
  33. package/lib/plugins/postcss/utils/load-module.d.ts.map +1 -0
  34. package/lib/plugins/postcss/utils/load-module.js +27 -0
  35. package/lib/plugins/postcss/utils/load-module.js.map +1 -0
  36. package/lib/plugins/postcss/utils/normalize-path.d.ts +3 -0
  37. package/lib/plugins/postcss/utils/normalize-path.d.ts.map +1 -0
  38. package/lib/plugins/postcss/utils/normalize-path.js +4 -0
  39. package/lib/plugins/postcss/utils/normalize-path.js.map +1 -0
  40. package/lib/rollup.js +1 -1
  41. package/lib/rollup.js.map +1 -1
  42. package/package.json +9 -8
@@ -1,521 +1,12 @@
1
1
  // Fork of rollup-plugin-postcss to fix https://github.com/egoist/rollup-plugin-postcss/issues/184.
2
2
  // The plugin seems to no longer be maintained and no fork was found.
3
- /* tslint:disable */
4
3
  /* eslint-disable */
5
4
  // @ts-nocheck
6
- // rollup-plugin-postcss v3.0.0
7
5
  import path from 'path';
8
6
  import { createFilter } from '@rollup/pluginutils';
9
7
  import Concat from 'concat-with-sourcemaps';
10
- import { createRequire } from 'module';
11
- import postcss from 'postcss';
12
- import pify from 'pify';
13
- import resolvePackage from 'resolve';
14
- import PQueue from 'p-queue';
15
- // from https://github.com/eemeli/safe-identifier
16
- // from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Lexical_grammar#keywords
17
- const reserved = new Set([
18
- 'break',
19
- 'case',
20
- 'catch',
21
- 'class',
22
- 'const',
23
- 'continue',
24
- 'debugger',
25
- 'default',
26
- 'delete',
27
- 'do',
28
- 'else',
29
- 'export',
30
- 'extends',
31
- 'false',
32
- 'finally',
33
- 'for',
34
- 'function',
35
- 'if',
36
- 'import',
37
- 'in',
38
- 'instanceof',
39
- 'new',
40
- 'null',
41
- 'return',
42
- 'super',
43
- 'switch',
44
- 'this',
45
- 'throw',
46
- 'true',
47
- 'try',
48
- 'typeof',
49
- 'var',
50
- 'void',
51
- 'while',
52
- 'with',
53
- 'let',
54
- 'static',
55
- 'yield',
56
- 'await',
57
- ]);
58
- // from https://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/
59
- function hashCode(str) {
60
- let hash = 0;
61
- for (let i = 0; i < str.length; ++i) {
62
- const char = str.charCodeAt(i);
63
- hash = (hash << 5) - hash + char;
64
- hash |= 0; // Convert to 32bit integer
65
- }
66
- return hash;
67
- }
68
- function identifier(key, unique) {
69
- if (unique)
70
- key += ` ${hashCode(key).toString(36)}`;
71
- const id = key.trim().replace(/\W+/g, '_');
72
- return reserved.has(id) || /^\d/.test(id) ? `_${id}` : id;
73
- }
74
- /**
75
- * Normalize path separators to forward slashes
76
- * @param {string} p - Path to normalize
77
- * @returns {string} Normalized path
78
- */
79
- function normalizePath(p) {
80
- return p?.replace(/\\+/g, '/') || '';
81
- }
82
- /**
83
- * Convert absolute path to relative path from current working directory
84
- * @param {string} filepath - Absolute file path
85
- * @returns {string} Relative path
86
- */
87
- function humanlizePath(filepath) {
88
- return normalizePath(path.relative(process.cwd(), filepath));
89
- }
90
- const require = createRequire(import.meta.url);
91
- const styleInjectPath = require.resolve('style-inject/dist/style-inject.es').replace(/[\\/]+/g, '/');
92
- /**
93
- * Escape CSS class name dashes for JavaScript identifiers
94
- */
95
- function escapeClassNameDashes(string) {
96
- return string.replace(/-+/g, (match) => {
97
- return `$${match.replace(/-/g, '_')}$`;
98
- });
99
- }
100
- /**
101
- * Ensure class name is a valid JavaScript identifier
102
- */
103
- function ensureClassName(name) {
104
- const escapedName = escapeClassNameDashes(name);
105
- return identifier(escapedName, false);
106
- }
107
- /**
108
- * Ensure PostCSS option is properly loaded
109
- */
110
- async function ensurePostCSSOption(option) {
111
- if (typeof option === 'string') {
112
- try {
113
- const { createRequire } = await import('module');
114
- const require = createRequire(import.meta.url);
115
- const resolvedPath = require.resolve(option);
116
- return await import(resolvedPath);
117
- }
118
- catch {
119
- return option;
120
- }
121
- }
122
- return option;
123
- }
124
- /**
125
- * Check if file is a CSS module
126
- */
127
- function isModuleFile(file) {
128
- return /\.module\.[a-z]{2,6}$/.test(file);
129
- }
130
- var postcssLoader = {
131
- name: 'postcss',
132
- alwaysProcess: true,
133
- async process({ code, map }) {
134
- // This is modified to not load postcss config.
135
- if (this.options.config !== false) {
136
- throw new Error('This is a fork of rollup-plugin-postcss that does not support loading postcss config. ' +
137
- 'Please set `config: false` in the plugin options.');
138
- }
139
- const { options } = this;
140
- const plugins = [...(options.postcss.plugins || [])];
141
- const shouldExtract = options.extract;
142
- const shouldInject = options.inject;
143
- const modulesExported = {};
144
- const autoModules = options.autoModules !== false && options.onlyModules !== true;
145
- const isAutoModule = autoModules && isModuleFile(this.id);
146
- const supportModules = autoModules ? isAutoModule : options.modules;
147
- if (supportModules) {
148
- const postcssModules = await import('postcss-modules');
149
- plugins.unshift(postcssModules.default({
150
- generateScopedName: process.env.ROLLUP_POSTCSS_TEST ? '[name]_[local]' : '[name]_[local]__[hash:base64:5]',
151
- ...options.modules,
152
- getJSON(filepath, json, outpath) {
153
- modulesExported[filepath] = json;
154
- if (typeof options.modules === 'object' && typeof options.modules.getJSON === 'function') {
155
- return options.modules.getJSON(filepath, json, outpath);
156
- }
157
- },
158
- }));
159
- }
160
- if (!shouldExtract && options.minimize) {
161
- const cssnano = await import('cssnano');
162
- plugins.push(cssnano.default(options.minimize));
163
- }
164
- const postcssOptions = {
165
- ...this.options.postcss,
166
- to: options.to || this.id,
167
- from: this.id,
168
- map: this.sourceMap
169
- ? shouldExtract
170
- ? { inline: false, annotation: false }
171
- : { inline: true, annotation: false }
172
- : false,
173
- };
174
- delete postcssOptions.plugins;
175
- postcssOptions.parser = await ensurePostCSSOption(postcssOptions.parser);
176
- postcssOptions.syntax = await ensurePostCSSOption(postcssOptions.syntax);
177
- postcssOptions.stringifier = await ensurePostCSSOption(postcssOptions.stringifier);
178
- if (map && postcssOptions.map) {
179
- postcssOptions.map.prev = typeof map === 'string' ? JSON.parse(map) : map;
180
- }
181
- if (plugins.length === 0) {
182
- const noopPlugin = () => ({
183
- postcssPlugin: 'postcss-noop-plugin',
184
- Once() { },
185
- });
186
- plugins.push(noopPlugin());
187
- }
188
- const result = await postcss(plugins).process(code, postcssOptions);
189
- for (const message of result.messages) {
190
- if (message.type === 'dependency') {
191
- this.dependencies.add(message.file);
192
- }
193
- }
194
- for (const warning of result.warnings()) {
195
- if (!warning.message) {
196
- warning.message = warning.text;
197
- }
198
- this.warn(warning);
199
- }
200
- const outputMap = result.map && JSON.parse(result.map.toString());
201
- if (outputMap?.sources) {
202
- outputMap.sources = outputMap.sources.map((v) => normalizePath(v));
203
- }
204
- let output = '';
205
- let extracted;
206
- if (options.namedExports) {
207
- const json = modulesExported[this.id];
208
- const getClassName = typeof options.namedExports === 'function' ? options.namedExports : ensureClassName;
209
- for (const name in json) {
210
- const newName = getClassName(name);
211
- // Log transformed class names
212
- // But skip this when namedExports is a function
213
- // Since a user like you can manually log that if you want
214
- if (name !== newName && typeof options.namedExports !== 'function') {
215
- this.warn(`Exported "${name}" as "${newName}" in ${humanlizePath(this.id)}`);
216
- }
217
- if (!json[newName]) {
218
- json[newName] = json[name];
219
- }
220
- output += `export var ${newName} = ${JSON.stringify(json[name])};\n`;
221
- }
222
- }
223
- const cssVariableName = identifier('css', true);
224
- if (shouldExtract) {
225
- output += `export default ${JSON.stringify(modulesExported[this.id])};`;
226
- extracted = {
227
- id: this.id,
228
- code: result.css,
229
- map: outputMap,
230
- };
231
- }
232
- else {
233
- const module = supportModules ? JSON.stringify(modulesExported[this.id]) : cssVariableName;
234
- output += `var ${cssVariableName} = ${JSON.stringify(result.css)};\n`;
235
- output += `export default ${module};\n`;
236
- output += `export var stylesheet=${JSON.stringify(result.css)};`;
237
- }
238
- if (!shouldExtract && shouldInject) {
239
- output +=
240
- typeof options.inject === 'function'
241
- ? options.inject(cssVariableName, this.id)
242
- : `\nimport styleInject from '${styleInjectPath}';\n` +
243
- `styleInject(${cssVariableName}${Object.keys(options.inject).length > 0 ? `,${JSON.stringify(options.inject)}` : ''});`;
244
- }
245
- return {
246
- code: output,
247
- map: outputMap,
248
- extracted,
249
- };
250
- },
251
- };
252
- /**
253
- * Load a module using modern ESM dynamic imports
254
- * @param {string} moduleId - The module to load
255
- * @returns {Promise<any>} The loaded module
256
- */
257
- async function loadModule(moduleId) {
258
- try {
259
- // Try to import the module directly
260
- return await import(moduleId);
261
- }
262
- catch {
263
- // If direct import fails, try resolving from current working directory
264
- try {
265
- const { createRequire } = await import('module');
266
- const require = createRequire(import.meta.url);
267
- const resolvedPath = require.resolve(moduleId);
268
- return await import(resolvedPath);
269
- }
270
- catch {
271
- // Return null if module cannot be loaded
272
- return null;
273
- }
274
- }
275
- }
276
- // This queue makes sure node-sass leaves one thread available for executing fs tasks
277
- // See: https://github.com/sass/node-sass/issues/857
278
- const threadPoolSize = process.env.UV_THREADPOOL_SIZE || 4;
279
- const workQueue = new PQueue({ concurrency: threadPoolSize - 1 });
280
- const moduleRe = /^~([a-z\d]|@).+/i;
281
- const getUrlOfPartial = (url) => {
282
- const parsedUrl = path.parse(url);
283
- return `${parsedUrl.dir}${path.sep}_${parsedUrl.base}`;
284
- };
285
- const resolvePromise = pify(resolvePackage);
286
- // List of supported SASS modules in the order of preference
287
- const sassModuleIds = ['sass', 'node-sass'];
288
- /* eslint import/no-anonymous-default-export: [2, {"allowObject": true}] */
289
- var sassLoader = {
290
- name: 'sass',
291
- test: /\.(sass|scss)$/,
292
- process({ code }) {
293
- return new Promise((resolve, reject) => {
294
- (async () => {
295
- const sassModule = await loadSassOrThrow();
296
- // accessing sassModule.default logs an error in latest versions
297
- const sass = sassModule.render ? sassModule : sassModule.default;
298
- const render = pify(sass.render.bind(sass));
299
- const data = this.options.data || '';
300
- workQueue.add(() => render({
301
- ...this.options,
302
- file: this.id,
303
- data: data + code,
304
- indentedSyntax: /\.sass$/.test(this.id),
305
- sourceMap: this.sourceMap,
306
- importer: [
307
- (url, importer, done) => {
308
- if (!moduleRe.test(url))
309
- return done({ file: url });
310
- const moduleUrl = url.slice(1);
311
- const partialUrl = getUrlOfPartial(moduleUrl);
312
- const options = {
313
- basedir: path.dirname(importer),
314
- extensions: ['.scss', '.sass', '.css'],
315
- };
316
- const finishImport = (id) => {
317
- done({
318
- // Do not add `.css` extension in order to inline the file
319
- file: id.endsWith('.css') ? id.replace(/\.css$/, '') : id,
320
- });
321
- };
322
- const next = () => {
323
- // Catch all resolving errors, return the original file and pass responsibility back to other custom importers
324
- done({ file: url });
325
- };
326
- // Give precedence to importing a partial
327
- resolvePromise(partialUrl, options)
328
- .then(finishImport)
329
- .catch((error) => {
330
- if (error.code === 'MODULE_NOT_FOUND' || error.code === 'ENOENT') {
331
- resolvePromise(moduleUrl, options).then(finishImport).catch(next);
332
- }
333
- else {
334
- next();
335
- }
336
- });
337
- },
338
- ].concat(this.options.importer || []),
339
- })
340
- .then((result) => {
341
- for (const file of result.stats.includedFiles) {
342
- this.dependencies.add(file);
343
- }
344
- resolve({
345
- code: result.css.toString(),
346
- map: result.map && result.map.toString(),
347
- });
348
- })
349
- .catch(reject));
350
- })();
351
- });
352
- },
353
- };
354
- async function loadSassOrThrow() {
355
- // Loading one of the supported modules
356
- for (const moduleId of sassModuleIds) {
357
- const module = await loadModule(moduleId);
358
- if (module) {
359
- return module;
360
- }
361
- }
362
- // Throwing exception if module can't be loaded
363
- throw new Error(`You need to install one of the following packages: ${sassModuleIds
364
- .map((moduleId) => `"${moduleId}"`)
365
- .join(', ')} in order to process SASS files`);
366
- }
367
- var stylusLoader = {
368
- name: 'stylus',
369
- test: /\.(styl|stylus)$/,
370
- async process({ code }) {
371
- const stylusModule = await loadModule('stylus');
372
- if (!stylusModule) {
373
- throw new Error('You need to install "stylus" package to process Stylus files');
374
- }
375
- const stylus = stylusModule.default || stylusModule;
376
- const style = stylus(code, {
377
- ...this.options,
378
- filename: this.id,
379
- sourcemap: this.sourceMap && {},
380
- });
381
- const renderAsync = pify(style.render.bind(style));
382
- try {
383
- const css = await renderAsync();
384
- const deps = style.deps();
385
- for (const dep of deps) {
386
- this.dependencies.add(dep);
387
- }
388
- return {
389
- code: css,
390
- map: style.sourcemap,
391
- };
392
- }
393
- catch (error) {
394
- throw new Error(`Stylus compilation failed: ${error.message}`);
395
- }
396
- },
397
- };
398
- var lessLoader = {
399
- name: 'less',
400
- test: /\.less$/,
401
- async process({ code }) {
402
- const lessModule = await loadModule('less');
403
- if (!lessModule) {
404
- throw new Error('You need to install "less" package to process Less files');
405
- }
406
- const less = lessModule.default || lessModule;
407
- const renderAsync = pify(less.render.bind(less));
408
- try {
409
- const { css, map: initialMap, imports, } = await renderAsync(code, {
410
- ...this.options,
411
- sourceMap: this.sourceMap && {},
412
- filename: this.id,
413
- });
414
- for (const dep of imports) {
415
- this.dependencies.add(dep);
416
- }
417
- let map = initialMap;
418
- if (map) {
419
- map = JSON.parse(map);
420
- map.sources = map.sources.map((source) => humanlizePath(source));
421
- }
422
- return {
423
- code: css,
424
- map,
425
- };
426
- }
427
- catch (error) {
428
- throw new Error(`Less compilation failed: ${error.message}`);
429
- }
430
- },
431
- };
432
- const matchFile = (filepath, condition) => {
433
- if (typeof condition === 'function') {
434
- return condition(filepath);
435
- }
436
- return condition && condition.test(filepath);
437
- };
438
- class Loaders {
439
- constructor(options = {}) {
440
- this.use = options.use.map((rule) => {
441
- if (typeof rule === 'string') {
442
- return [rule];
443
- }
444
- if (Array.isArray(rule)) {
445
- return rule;
446
- }
447
- throw new TypeError('The rule in `use` option must be string or Array!');
448
- });
449
- this.loaders = [];
450
- const extensions = options.extensions || ['.css', '.sss', '.pcss'];
451
- const customPostcssLoader = {
452
- ...postcssLoader,
453
- test: (filepath) => extensions.some((ext) => path.extname(filepath) === ext),
454
- };
455
- this.registerLoader(customPostcssLoader);
456
- this.registerLoader(sassLoader);
457
- this.registerLoader(stylusLoader);
458
- this.registerLoader(lessLoader);
459
- if (options.loaders) {
460
- options.loaders.forEach((loader) => this.registerLoader(loader));
461
- }
462
- }
463
- registerLoader(loader) {
464
- const existing = this.getLoader(loader.name);
465
- if (existing) {
466
- this.removeLoader(loader.name);
467
- }
468
- this.loaders.push(loader);
469
- return this;
470
- }
471
- removeLoader(name) {
472
- this.loaders = this.loaders.filter((loader) => loader.name !== name);
473
- return this;
474
- }
475
- isSupported(filepath) {
476
- return this.loaders.some((loader) => {
477
- return matchFile(filepath, loader.test);
478
- });
479
- }
480
- /**
481
- * Process the resource with loaders in serial
482
- * @param {object} resource
483
- * @param {string} resource.code
484
- * @param {any} resource.map
485
- * @param {object} context
486
- * @param {string} context.id The absolute path to resource
487
- * @param {boolean | 'inline'} context.sourceMap
488
- * @param {Set<string>} context.dependencies A set of dependencies to watch
489
- * @returns {{code: string, map?: any}}
490
- */
491
- async process({ code, map }, context) {
492
- const loaderFunctions = this.use
493
- .slice()
494
- .reverse()
495
- .map(([name, options]) => {
496
- const loader = this.getLoader(name);
497
- const loaderContext = {
498
- options: options || {},
499
- ...context,
500
- };
501
- return (v) => {
502
- if (loader.alwaysProcess || matchFile(loaderContext.id, loader.test)) {
503
- return loader.process.call(loaderContext, v);
504
- }
505
- // Otherwise directly return input value
506
- return v;
507
- };
508
- });
509
- let result = { code, map };
510
- for (const loaderFn of loaderFunctions) {
511
- result = await loaderFn(result);
512
- }
513
- return result;
514
- }
515
- getLoader(name) {
516
- return this.loaders.find((loader) => loader.name === name);
517
- }
518
- }
8
+ import Loaders from './loaders.js';
9
+ import normalizePath from './utils/normalize-path.js';
519
10
  /**
520
11
  * The options that could be `boolean` or `object`
521
12
  * We convert it to an object when it's truthy
@@ -548,7 +39,7 @@ function getRecursiveImportOrder(id, getModuleInfo, seen = new Set()) {
548
39
  return result;
549
40
  }
550
41
  /* eslint import/no-anonymous-default-export: [2, {"allowArrowFunction": true}] */
551
- var index = (options = {}) => {
42
+ export default (options = {}) => {
552
43
  const filter = createFilter(options.include, options.exclude);
553
44
  const postcssPlugins = Array.isArray(options.plugins) ? options.plugins.filter(Boolean) : options.plugins;
554
45
  const { sourceMap } = options;
@@ -578,14 +69,13 @@ var index = (options = {}) => {
578
69
  exec: options.exec,
579
70
  },
580
71
  };
581
- let use = ['sass', 'stylus', 'less'];
72
+ let use = ['sass', 'less'];
582
73
  if (Array.isArray(options.use)) {
583
- ({ use } = options);
74
+ use = options.use;
584
75
  }
585
76
  else if (options.use !== null && typeof options.use === 'object') {
586
77
  use = [
587
78
  ['sass', options.use.sass || {}],
588
- ['stylus', options.use.stylus || {}],
589
79
  ['less', options.use.less || {}],
590
80
  ];
591
81
  }
@@ -634,6 +124,7 @@ var index = (options = {}) => {
634
124
  augmentChunkHash() {
635
125
  if (extracted.size === 0)
636
126
  return;
127
+ // eslint-disable-next-line unicorn/no-reduce
637
128
  const extractedValue = [...extracted].reduce((object, [key, value]) => ({
638
129
  ...object,
639
130
  [key]: value,
@@ -680,7 +171,7 @@ var index = (options = {}) => {
680
171
  code,
681
172
  map: sourceMap === true && concat.sourceMap,
682
173
  codeFileName: fileName,
683
- mapFileName: `${fileName}.map`,
174
+ mapFileName: fileName + '.map',
684
175
  };
685
176
  };
686
177
  if (options.onExtract) {
@@ -689,9 +180,7 @@ var index = (options = {}) => {
689
180
  return;
690
181
  }
691
182
  }
692
- const { code: initialCode, codeFileName, map: initialMap, mapFileName } = getExtracted();
693
- let code = initialCode;
694
- let map = initialMap;
183
+ let { code, codeFileName, map, mapFileName } = getExtracted();
695
184
  // Perform cssnano on the extracted file
696
185
  if (postcssLoaderOptions.minimize) {
697
186
  const cssOptions = {};
@@ -725,5 +214,4 @@ var index = (options = {}) => {
725
214
  },
726
215
  };
727
216
  };
728
- export { index as default };
729
217
  //# sourceMappingURL=index.js.map