@lwrjs/module-bundler 0.12.0-alpha.2 → 0.12.0-alpha.3

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.
@@ -27,6 +27,7 @@ __export(exports, {
27
27
  default: () => esm_bundle_provider_default
28
28
  });
29
29
  var import_rollup = __toModule(require("rollup"));
30
+ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
30
31
  var import_rollup_esm_bundler_plugin = __toModule(require("./utils/rollup-esm-bundler-plugin.cjs"));
31
32
  var import_esbuild_utils = __toModule(require("./utils/esbuild-utils.cjs"));
32
33
  var import_bundle_common = __toModule(require("./utils/bundle-common.cjs"));
@@ -50,27 +51,35 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
50
51
  const requiredImports = new Map();
51
52
  const dynamicImports = new Map();
52
53
  const rootModuleDef = await moduleRegistry.getLinkedModule(moduleId, runtimeEnvironment, runtimeParams);
53
- const bundle = await (0, import_rollup.rollup)({
54
- input: moduleId.specifier,
55
- plugins: [
56
- (0, import_rollup_esm_bundler_plugin.bundleDefinitions)({
57
- rootModuleDef,
58
- runtimeEnvironment,
59
- moduleRegistry,
60
- exclude,
61
- alias,
62
- runtimeParams,
63
- requiredImports,
64
- dynamicImports
65
- })
66
- ],
67
- makeAbsoluteExternalsRelative: "ifRelativeSource"
68
- });
69
- const result = await bundle.generate({
70
- paths: (id2) => {
71
- return external[id2] || id2;
72
- },
73
- sourcemap: true
54
+ const result = await (0, import_instrumentation.getTracer)().trace({
55
+ name: import_instrumentation.BundleSpan.Rollup,
56
+ attributes: {
57
+ specifier: moduleId.specifier,
58
+ format: "esm"
59
+ }
60
+ }, async () => {
61
+ const bundle = await (0, import_rollup.rollup)({
62
+ input: moduleId.specifier,
63
+ plugins: [
64
+ (0, import_rollup_esm_bundler_plugin.bundleDefinitions)({
65
+ rootModuleDef,
66
+ runtimeEnvironment,
67
+ moduleRegistry,
68
+ exclude,
69
+ alias,
70
+ runtimeParams,
71
+ requiredImports,
72
+ dynamicImports
73
+ })
74
+ ],
75
+ makeAbsoluteExternalsRelative: "ifRelativeSource"
76
+ });
77
+ return bundle.generate({
78
+ paths: (id2) => {
79
+ return external[id2] || id2;
80
+ },
81
+ sourcemap: true
82
+ });
74
83
  });
75
84
  const bundleCode = result.output[0].code;
76
85
  const bundleMap = result.output[0].map;
@@ -26,9 +26,10 @@ __markAsModule(exports);
26
26
  __export(exports, {
27
27
  LwrModuleBundler: () => LwrModuleBundler
28
28
  });
29
+ var import_path = __toModule(require("path"));
29
30
  var import_diagnostics = __toModule(require("@lwrjs/diagnostics"));
30
31
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
31
- var import_path = __toModule(require("path"));
32
+ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
32
33
  var TASK_POOL = new import_shared_utils.TaskPool();
33
34
  var LwrModuleBundler = class {
34
35
  constructor(config, globalConfig) {
@@ -65,21 +66,28 @@ var LwrModuleBundler = class {
65
66
  return bundleDef;
66
67
  }
67
68
  }
68
- return this.inflightBundleDefinitions.execute(cacheKey, () => {
69
- return TASK_POOL.execute(async () => {
70
- for (const bundler of this.providers) {
71
- const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
72
- if (bundleDef) {
73
- if (!cacheDisabled) {
74
- this.cache.set(cacheKey, bundleDef);
69
+ return (0, import_instrumentation.getTracer)().trace({
70
+ name: import_instrumentation.BundleSpan.GetBundle,
71
+ attributes: {
72
+ specifier: moduleId.specifier
73
+ }
74
+ }, () => {
75
+ return this.inflightBundleDefinitions.execute(cacheKey, () => {
76
+ return TASK_POOL.execute(async () => {
77
+ for (const bundler of this.providers) {
78
+ const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
79
+ if (bundleDef) {
80
+ if (!cacheDisabled) {
81
+ this.cache.set(cacheKey, bundleDef);
82
+ }
83
+ return bundleDef;
75
84
  }
76
- return bundleDef;
77
85
  }
78
- }
79
- throw (0, import_diagnostics.createSingleDiagnosticError)({
80
- description: import_diagnostics.descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier)
81
- }, import_diagnostics.LwrUnresolvableError);
82
- }, this);
86
+ throw (0, import_diagnostics.createSingleDiagnosticError)({
87
+ description: import_diagnostics.descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier)
88
+ }, import_diagnostics.LwrUnresolvableError);
89
+ }, this);
90
+ });
83
91
  });
84
92
  }
85
93
  async resolveModuleUri(moduleId, runtimeEnvironment, runtimeParams, signature) {
@@ -29,6 +29,7 @@ __export(exports, {
29
29
  var import_shared_utils = __toModule(require("@lwrjs/shared-utils"));
30
30
  var import_rollup = __toModule(require("rollup"));
31
31
  var import_plugin_replace = __toModule(require("@rollup/plugin-replace"));
32
+ var import_instrumentation = __toModule(require("@lwrjs/instrumentation"));
32
33
  var import_rollup_amd_bundler_plugin = __toModule(require("./rollup-amd-bundler-plugin.cjs"));
33
34
  var import_bundle_common = __toModule(require("./bundle-common.cjs"));
34
35
  var AMD_DEFINE = "LWR.define";
@@ -61,11 +62,19 @@ async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = fal
61
62
  "process.env.NODE_ENV": JSON.stringify("production"),
62
63
  preventAssignment: false
63
64
  }));
64
- const bundler = await (0, import_rollup.rollup)({input: id, plugins});
65
- const {output} = await bundler.generate({
66
- amd: {id, define: AMD_DEFINE},
67
- exports: "named",
68
- format: "amd"
65
+ const {output} = await (0, import_instrumentation.getTracer)().trace({
66
+ name: import_instrumentation.BundleSpan.Rollup,
67
+ attributes: {
68
+ specifier: id,
69
+ format: "amd"
70
+ }
71
+ }, async () => {
72
+ const bundler = await (0, import_rollup.rollup)({input: id, plugins});
73
+ return bundler.generate({
74
+ amd: {id, define: AMD_DEFINE},
75
+ exports: "named",
76
+ format: "amd"
77
+ });
69
78
  });
70
79
  let code = output[0].code;
71
80
  if (unVersionedAliases) {
@@ -1,4 +1,5 @@
1
1
  import { rollup } from 'rollup';
2
+ import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
2
3
  import { bundleDefinitions } from './utils/rollup-esm-bundler-plugin.js';
3
4
  import { minifyJavascript } from './utils/esbuild-utils.js';
4
5
  import { overrideBundleConfig } from './utils/bundle-common.js';
@@ -21,29 +22,37 @@ async function esmBundler(moduleId, moduleRegistry, runtimeEnvironment, runtimeP
21
22
  const requiredImports = new Map();
22
23
  const dynamicImports = new Map();
23
24
  const rootModuleDef = await moduleRegistry.getLinkedModule(moduleId, runtimeEnvironment, runtimeParams);
24
- const bundle = await rollup({
25
- input: moduleId.specifier,
26
- plugins: [
27
- bundleDefinitions({
28
- rootModuleDef,
29
- runtimeEnvironment,
30
- moduleRegistry,
31
- exclude,
32
- alias,
33
- runtimeParams,
34
- requiredImports,
35
- dynamicImports,
36
- }),
37
- ],
38
- makeAbsoluteExternalsRelative: 'ifRelativeSource', // Fix for breaking changes in https://github.com/rollup/rollup/pull/4021
39
- });
40
- const result = await bundle.generate({
41
- paths: (id) => {
42
- // The fallback on id is important due to a rollup semantic issue:
43
- // https://github.com/rollup/rollup/issues/3831
44
- return external[id] || id;
25
+ const result = await getTracer().trace({
26
+ name: BundleSpan.Rollup,
27
+ attributes: {
28
+ specifier: moduleId.specifier,
29
+ format: 'esm',
45
30
  },
46
- sourcemap: true,
31
+ }, async () => {
32
+ const bundle = await rollup({
33
+ input: moduleId.specifier,
34
+ plugins: [
35
+ bundleDefinitions({
36
+ rootModuleDef,
37
+ runtimeEnvironment,
38
+ moduleRegistry,
39
+ exclude,
40
+ alias,
41
+ runtimeParams,
42
+ requiredImports,
43
+ dynamicImports,
44
+ }),
45
+ ],
46
+ makeAbsoluteExternalsRelative: 'ifRelativeSource', // Fix for breaking changes in https://github.com/rollup/rollup/pull/4021
47
+ });
48
+ return bundle.generate({
49
+ paths: (id) => {
50
+ // The fallback on id is important due to a rollup semantic issue:
51
+ // https://github.com/rollup/rollup/issues/3831
52
+ return external[id] || id;
53
+ },
54
+ sourcemap: true,
55
+ });
47
56
  });
48
57
  const bundleCode = result.output[0].code;
49
58
  const bundleMap = result.output[0].map;
package/build/es/index.js CHANGED
@@ -1,6 +1,7 @@
1
+ import { join } from 'path';
1
2
  import { LwrUnresolvableError, createSingleDiagnosticError, descriptions } from '@lwrjs/diagnostics';
2
3
  import { getCacheKeyFromJson, InflightTasks, TaskPool } from '@lwrjs/shared-utils';
3
- import { join } from 'path';
4
+ import { getTracer, BundleSpan } from '@lwrjs/instrumentation';
4
5
  const TASK_POOL = new TaskPool();
5
6
  export class LwrModuleBundler {
6
7
  constructor(config, globalConfig) {
@@ -46,25 +47,30 @@ export class LwrModuleBundler {
46
47
  return bundleDef;
47
48
  }
48
49
  }
49
- return this.inflightBundleDefinitions.execute(cacheKey, () => {
50
- // TODO add to profiling
51
- // console.log('[INFO] Create Bundle: ', cacheKey);
52
- // Run theses tasks in a task pool to throttle parallel requests.
53
- return TASK_POOL.execute(async () => {
54
- for (const bundler of this.providers) {
55
- // eslint-disable-next-line no-await-in-loop
56
- const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
57
- if (bundleDef) {
58
- if (!cacheDisabled) {
59
- this.cache.set(cacheKey, bundleDef);
50
+ return getTracer().trace({
51
+ name: BundleSpan.GetBundle,
52
+ attributes: {
53
+ specifier: moduleId.specifier,
54
+ },
55
+ }, () => {
56
+ return this.inflightBundleDefinitions.execute(cacheKey, () => {
57
+ // Run theses tasks in a task pool to throttle parallel requests.
58
+ return TASK_POOL.execute(async () => {
59
+ for (const bundler of this.providers) {
60
+ // eslint-disable-next-line no-await-in-loop
61
+ const bundleDef = await bundler.bundle(moduleId, runtimeEnvironment, runtimeParams, bundleConfigOverrides);
62
+ if (bundleDef) {
63
+ if (!cacheDisabled) {
64
+ this.cache.set(cacheKey, bundleDef);
65
+ }
66
+ return bundleDef;
60
67
  }
61
- return bundleDef;
62
68
  }
63
- }
64
- throw createSingleDiagnosticError({
65
- description: descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier),
66
- }, LwrUnresolvableError);
67
- }, this);
69
+ throw createSingleDiagnosticError({
70
+ description: descriptions.UNRESOLVABLE.BUNDLE(moduleId.specifier),
71
+ }, LwrUnresolvableError);
72
+ }, this);
73
+ });
68
74
  });
69
75
  }
70
76
  /**
@@ -1,6 +1,7 @@
1
1
  import { GraphDepth, createAmdAlias, explodeSpecifier, getModuleGraphs, getSpecifier, getGroupName, isGroupie, getCacheKeyFromJson, } from '@lwrjs/shared-utils';
2
2
  import { rollup } from 'rollup';
3
3
  import replace from '@rollup/plugin-replace';
4
+ import { BundleSpan, getTracer } from '@lwrjs/instrumentation';
4
5
  import { bundleDefinitions } from './rollup-amd-bundler-plugin.js';
5
6
  import { overrideBundleConfig } from './bundle-common.js';
6
7
  const AMD_DEFINE = 'LWR.define';
@@ -45,11 +46,19 @@ async function bundle(id, moduleGraphs, minify = false, unVersionedAliases = fal
45
46
  'process.env.NODE_ENV': JSON.stringify('production'),
46
47
  preventAssignment: false,
47
48
  }));
48
- const bundler = await rollup({ input: id, plugins });
49
- const { output } = await bundler.generate({
50
- amd: { id, define: AMD_DEFINE },
51
- exports: 'named',
52
- format: 'amd',
49
+ const { output } = await getTracer().trace({
50
+ name: BundleSpan.Rollup,
51
+ attributes: {
52
+ specifier: id,
53
+ format: 'amd',
54
+ },
55
+ }, async () => {
56
+ const bundler = await rollup({ input: id, plugins });
57
+ return bundler.generate({
58
+ amd: { id, define: AMD_DEFINE },
59
+ exports: 'named',
60
+ format: 'amd',
61
+ });
53
62
  });
54
63
  let code = output[0].code;
55
64
  if (unVersionedAliases) {
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
7
- "version": "0.12.0-alpha.2",
7
+ "version": "0.12.0-alpha.3",
8
8
  "homepage": "https://developer.salesforce.com/docs/platform/lwr/overview",
9
9
  "repository": {
10
10
  "type": "git",
@@ -47,13 +47,14 @@
47
47
  "build/**/*.d.ts"
48
48
  ],
49
49
  "dependencies": {
50
- "@lwrjs/diagnostics": "0.12.0-alpha.2",
51
- "@lwrjs/shared-utils": "0.12.0-alpha.2",
50
+ "@lwrjs/diagnostics": "0.12.0-alpha.3",
51
+ "@lwrjs/instrumentation": "0.12.0-alpha.3",
52
+ "@lwrjs/shared-utils": "0.12.0-alpha.3",
52
53
  "@rollup/plugin-replace": "^2.4.2",
53
54
  "rollup": "^2.78.0"
54
55
  },
55
56
  "devDependencies": {
56
- "@lwrjs/types": "0.12.0-alpha.2",
57
+ "@lwrjs/types": "0.12.0-alpha.3",
57
58
  "jest": "^26.6.3",
58
59
  "ts-jest": "^26.5.6"
59
60
  },
@@ -69,5 +70,5 @@
69
70
  "volta": {
70
71
  "extends": "../../../package.json"
71
72
  },
72
- "gitHead": "586a2aa659882483af9249dc3db7fe07bc842a25"
73
+ "gitHead": "48f97b40cbacce6cd6a6faee9206a465832c6774"
73
74
  }