@parcel/transformer-babel 2.0.0-nightly.1298 → 2.0.0-nightly.1303

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.
@@ -72,7 +72,8 @@ var _default = new (_plugin().Transformer)({
72
72
  asset,
73
73
  config,
74
74
  logger,
75
- options
75
+ options,
76
+ tracer
76
77
  }) {
77
78
  try {
78
79
  if (config !== null && config !== void 0 && config.config) {
@@ -82,14 +83,16 @@ var _default = new (_plugin().Transformer)({
82
83
  options,
83
84
  logger,
84
85
  babelOptions: config,
85
- additionalPlugins: asset.meta.babelPlugins
86
+ additionalPlugins: asset.meta.babelPlugins,
87
+ tracer
86
88
  });
87
89
  } else {
88
90
  await (0, _babel.default)({
89
91
  asset,
90
92
  options,
91
93
  logger,
92
- babelOptions: config
94
+ babelOptions: config,
95
+ tracer
93
96
  });
94
97
  }
95
98
  }
package/lib/babel7.js CHANGED
@@ -61,7 +61,8 @@ async function babel7(opts) {
61
61
  asset,
62
62
  options,
63
63
  babelOptions,
64
- additionalPlugins = []
64
+ additionalPlugins = [],
65
+ tracer
65
66
  } = opts;
66
67
  const babelCore = await options.packageManager.require('@babel/core', asset.filePath, {
67
68
  range: '^7.12.0',
@@ -91,6 +92,23 @@ async function babel7(opts) {
91
92
  outputFormat: asset.env.outputFormat
92
93
  }
93
94
  };
95
+
96
+ if (tracer.enabled) {
97
+ config.wrapPluginVisitorMethod = (key, nodeType, fn) => {
98
+ return function () {
99
+ let pluginKey = key;
100
+
101
+ if (pluginKey.startsWith(options.projectRoot)) {
102
+ pluginKey = _path().default.relative(options.projectRoot, pluginKey);
103
+ }
104
+
105
+ const measurement = tracer.createMeasurement(pluginKey, nodeType, _path().default.relative(options.projectRoot, asset.filePath));
106
+ fn.apply(this, arguments);
107
+ measurement && measurement.end();
108
+ };
109
+ };
110
+ }
111
+
94
112
  let ast = await asset.getAST();
95
113
  let res;
96
114
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@parcel/transformer-babel",
3
- "version": "2.0.0-nightly.1298+eb76826da",
3
+ "version": "2.0.0-nightly.1303+cd4336412",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,13 +17,13 @@
17
17
  "source": "src/BabelTransformer.js",
18
18
  "engines": {
19
19
  "node": ">= 12.0.0",
20
- "parcel": "2.0.0-nightly.1296+eb76826da"
20
+ "parcel": "2.0.0-nightly.1301+cd4336412"
21
21
  },
22
22
  "dependencies": {
23
- "@parcel/diagnostic": "2.0.0-nightly.1298+eb76826da",
24
- "@parcel/plugin": "2.0.0-nightly.1298+eb76826da",
23
+ "@parcel/diagnostic": "2.0.0-nightly.1303+cd4336412",
24
+ "@parcel/plugin": "2.0.0-nightly.1303+cd4336412",
25
25
  "@parcel/source-map": "^2.1.1",
26
- "@parcel/utils": "2.0.0-nightly.1298+eb76826da",
26
+ "@parcel/utils": "2.0.0-nightly.1303+cd4336412",
27
27
  "browserslist": "^4.6.6",
28
28
  "json5": "^2.2.0",
29
29
  "nullthrows": "^1.1.1",
@@ -33,7 +33,7 @@
33
33
  "@babel/core": "^7.12.0",
34
34
  "@babel/preset-env": "^7.0.0",
35
35
  "@babel/types": "^7.12.0",
36
- "@parcel/types": "2.0.0-nightly.1298+eb76826da"
36
+ "@parcel/types": "2.0.0-nightly.1303+cd4336412"
37
37
  },
38
- "gitHead": "eb76826da305db1e5668bb9b0c1cb5dbe0951a4c"
38
+ "gitHead": "cd4336412242b6d6da40ef6cba8e7ac99c72b090"
39
39
  }
@@ -17,7 +17,7 @@ export default (new Transformer({
17
17
  return ast.type === 'babel' && semver.satisfies(ast.version, '^7.0.0');
18
18
  },
19
19
 
20
- async transform({asset, config, logger, options}) {
20
+ async transform({asset, config, logger, options, tracer}) {
21
21
  try {
22
22
  if (config?.config) {
23
23
  if (
@@ -30,9 +30,16 @@ export default (new Transformer({
30
30
  logger,
31
31
  babelOptions: config,
32
32
  additionalPlugins: asset.meta.babelPlugins,
33
+ tracer,
33
34
  });
34
35
  } else {
35
- await babel7({asset, options, logger, babelOptions: config});
36
+ await babel7({
37
+ asset,
38
+ options,
39
+ logger,
40
+ babelOptions: config,
41
+ tracer,
42
+ });
36
43
  }
37
44
  }
38
45
 
package/src/babel7.js CHANGED
@@ -4,6 +4,7 @@ import type {
4
4
  MutableAsset,
5
5
  AST,
6
6
  PluginOptions,
7
+ PluginTracer,
7
8
  PluginLogger,
8
9
  } from '@parcel/types';
9
10
  import typeof * as BabelCore from '@babel/core';
@@ -25,12 +26,13 @@ type Babel7TransformOptions = {|
25
26
  logger: PluginLogger,
26
27
  babelOptions: any,
27
28
  additionalPlugins?: Array<any>,
29
+ tracer: PluginTracer,
28
30
  |};
29
31
 
30
32
  export default async function babel7(
31
33
  opts: Babel7TransformOptions,
32
34
  ): Promise<?AST> {
33
- let {asset, options, babelOptions, additionalPlugins = []} = opts;
35
+ let {asset, options, babelOptions, additionalPlugins = [], tracer} = opts;
34
36
  const babelCore: BabelCore = await options.packageManager.require(
35
37
  '@babel/core',
36
38
  asset.filePath,
@@ -74,6 +76,28 @@ export default async function babel7(
74
76
  },
75
77
  };
76
78
 
79
+ if (tracer.enabled) {
80
+ config.wrapPluginVisitorMethod = (
81
+ key: string,
82
+ nodeType: string,
83
+ fn: Function,
84
+ ) => {
85
+ return function () {
86
+ let pluginKey = key;
87
+ if (pluginKey.startsWith(options.projectRoot)) {
88
+ pluginKey = path.relative(options.projectRoot, pluginKey);
89
+ }
90
+ const measurement = tracer.createMeasurement(
91
+ pluginKey,
92
+ nodeType,
93
+ path.relative(options.projectRoot, asset.filePath),
94
+ );
95
+ fn.apply(this, arguments);
96
+ measurement && measurement.end();
97
+ };
98
+ };
99
+ }
100
+
77
101
  let ast = await asset.getAST();
78
102
  let res;
79
103
  if (ast) {