@atlaspack/packager-js 2.14.0 → 2.14.1-canary.6
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/LICENSE +201 -0
- package/lib/CJSOutputFormat.js +36 -0
- package/lib/DevPackager.js +193 -0
- package/lib/ESMOutputFormat.js +106 -0
- package/lib/GlobalOutputFormat.js +19 -0
- package/lib/ScopeHoistingPackager.js +1092 -0
- package/lib/dev-prelude.js +145 -0
- package/lib/helpers.js +129 -0
- package/lib/index.js +153 -0
- package/lib/utils.js +68 -0
- package/package.json +10 -9
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
// modules are defined as an array
|
|
2
|
+
// [ module function, map of requires ]
|
|
3
|
+
//
|
|
4
|
+
// map of requires is short require name -> numeric require
|
|
5
|
+
//
|
|
6
|
+
// anything defined in a previous bundle is accessed via the
|
|
7
|
+
// orig method which is the require for previous bundles
|
|
8
|
+
|
|
9
|
+
(function (modules, entry, mainEntry, parcelRequireName, globalName) {
|
|
10
|
+
/* eslint-disable no-undef */
|
|
11
|
+
var globalObject =
|
|
12
|
+
typeof globalThis !== 'undefined'
|
|
13
|
+
? globalThis
|
|
14
|
+
: typeof self !== 'undefined'
|
|
15
|
+
? self
|
|
16
|
+
: typeof window !== 'undefined'
|
|
17
|
+
? window
|
|
18
|
+
: typeof global !== 'undefined'
|
|
19
|
+
? global
|
|
20
|
+
: {};
|
|
21
|
+
/* eslint-enable no-undef */
|
|
22
|
+
|
|
23
|
+
// Save the require from previous bundle to this closure if any
|
|
24
|
+
var previousRequire =
|
|
25
|
+
typeof globalObject[parcelRequireName] === 'function' &&
|
|
26
|
+
globalObject[parcelRequireName];
|
|
27
|
+
|
|
28
|
+
var cache = previousRequire.cache || {};
|
|
29
|
+
// Do not use `require` to prevent Webpack from trying to bundle this call
|
|
30
|
+
var nodeRequire =
|
|
31
|
+
typeof module !== 'undefined' &&
|
|
32
|
+
typeof module.require === 'function' &&
|
|
33
|
+
module.require.bind(module);
|
|
34
|
+
|
|
35
|
+
function newRequire(name, jumped) {
|
|
36
|
+
if (!cache[name]) {
|
|
37
|
+
if (!modules[name]) {
|
|
38
|
+
// if we cannot find the module within our internal map or
|
|
39
|
+
// cache jump to the current global require ie. the last bundle
|
|
40
|
+
// that was added to the page.
|
|
41
|
+
var currentRequire =
|
|
42
|
+
typeof globalObject[parcelRequireName] === 'function' &&
|
|
43
|
+
globalObject[parcelRequireName];
|
|
44
|
+
if (!jumped && currentRequire) {
|
|
45
|
+
return currentRequire(name, true);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// If there are other bundles on this page the require from the
|
|
49
|
+
// previous one is saved to 'previousRequire'. Repeat this as
|
|
50
|
+
// many times as there are bundles until the module is found or
|
|
51
|
+
// we exhaust the require chain.
|
|
52
|
+
if (previousRequire) {
|
|
53
|
+
return previousRequire(name, true);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Try the node require function if it exists.
|
|
57
|
+
if (nodeRequire && typeof name === 'string') {
|
|
58
|
+
return nodeRequire(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
var err = new Error("Cannot find module '" + name + "'");
|
|
62
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
63
|
+
throw err;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
localRequire.resolve = resolve;
|
|
67
|
+
localRequire.cache = {};
|
|
68
|
+
|
|
69
|
+
var module = (cache[name] = new newRequire.Module(name));
|
|
70
|
+
|
|
71
|
+
modules[name][0].call(
|
|
72
|
+
module.exports,
|
|
73
|
+
localRequire,
|
|
74
|
+
module,
|
|
75
|
+
module.exports,
|
|
76
|
+
globalObject
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return cache[name].exports;
|
|
81
|
+
|
|
82
|
+
function localRequire(x) {
|
|
83
|
+
var res = localRequire.resolve(x);
|
|
84
|
+
return res === false ? {} : newRequire(res);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function resolve(x) {
|
|
88
|
+
var id = modules[name][1][x];
|
|
89
|
+
return id != null ? id : x;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function Module(moduleName) {
|
|
94
|
+
this.id = moduleName;
|
|
95
|
+
this.bundle = newRequire;
|
|
96
|
+
this.exports = {};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
newRequire.isParcelRequire = true;
|
|
100
|
+
newRequire.Module = Module;
|
|
101
|
+
newRequire.modules = modules;
|
|
102
|
+
newRequire.cache = cache;
|
|
103
|
+
newRequire.parent = previousRequire;
|
|
104
|
+
newRequire.register = function (id, exports) {
|
|
105
|
+
modules[id] = [
|
|
106
|
+
function (require, module) {
|
|
107
|
+
module.exports = exports;
|
|
108
|
+
},
|
|
109
|
+
{},
|
|
110
|
+
];
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
Object.defineProperty(newRequire, 'root', {
|
|
114
|
+
get: function () {
|
|
115
|
+
return globalObject[parcelRequireName];
|
|
116
|
+
},
|
|
117
|
+
});
|
|
118
|
+
|
|
119
|
+
globalObject[parcelRequireName] = newRequire;
|
|
120
|
+
|
|
121
|
+
for (var i = 0; i < entry.length; i++) {
|
|
122
|
+
newRequire(entry[i]);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
if (mainEntry) {
|
|
126
|
+
// Expose entry point to Node, AMD or browser globals
|
|
127
|
+
// Based on https://github.com/ForbesLindesay/umd/blob/master/template.js
|
|
128
|
+
var mainExports = newRequire(mainEntry);
|
|
129
|
+
|
|
130
|
+
// CommonJS
|
|
131
|
+
if (typeof exports === 'object' && typeof module !== 'undefined') {
|
|
132
|
+
module.exports = mainExports;
|
|
133
|
+
|
|
134
|
+
// RequireJS
|
|
135
|
+
} else if (typeof define === 'function' && define.amd) {
|
|
136
|
+
define(function () {
|
|
137
|
+
return mainExports;
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
// <script>
|
|
141
|
+
} else if (globalName) {
|
|
142
|
+
this[globalName] = mainExports;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
package/lib/helpers.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.prelude = exports.helpers = exports.fnExpr = exports.bundleQueuePrelude = void 0;
|
|
7
|
+
const prelude = parcelRequireName => `
|
|
8
|
+
var $parcel$modules = {};
|
|
9
|
+
var $parcel$inits = {};
|
|
10
|
+
|
|
11
|
+
var parcelRequire = $parcel$global[${JSON.stringify(parcelRequireName)}];
|
|
12
|
+
|
|
13
|
+
if (parcelRequire == null) {
|
|
14
|
+
parcelRequire = function(id) {
|
|
15
|
+
if (id in $parcel$modules) {
|
|
16
|
+
return $parcel$modules[id].exports;
|
|
17
|
+
}
|
|
18
|
+
if (id in $parcel$inits) {
|
|
19
|
+
var init = $parcel$inits[id];
|
|
20
|
+
delete $parcel$inits[id];
|
|
21
|
+
var module = {id: id, exports: {}};
|
|
22
|
+
$parcel$modules[id] = module;
|
|
23
|
+
init.call(module.exports, module, module.exports);
|
|
24
|
+
return module.exports;
|
|
25
|
+
}
|
|
26
|
+
var err = new Error("Cannot find module '" + id + "'");
|
|
27
|
+
err.code = 'MODULE_NOT_FOUND';
|
|
28
|
+
throw err;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
parcelRequire.register = function register(id, init) {
|
|
32
|
+
$parcel$inits[id] = init;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
$parcel$global[${JSON.stringify(parcelRequireName)}] = parcelRequire;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
var parcelRegister = parcelRequire.register;
|
|
39
|
+
`;
|
|
40
|
+
exports.prelude = prelude;
|
|
41
|
+
const fnExpr = (env, params, body) => {
|
|
42
|
+
let block = `{ ${body.join(' ')} }`;
|
|
43
|
+
if (env.supports('arrow-functions')) {
|
|
44
|
+
return `(${params.join(', ')}) => ${block}`;
|
|
45
|
+
}
|
|
46
|
+
return `function (${params.join(', ')}) ${block}`;
|
|
47
|
+
};
|
|
48
|
+
exports.fnExpr = fnExpr;
|
|
49
|
+
const bundleQueuePrelude = env => `
|
|
50
|
+
if (!$parcel$global.lb) {
|
|
51
|
+
// Set of loaded bundles
|
|
52
|
+
$parcel$global.lb = new Set();
|
|
53
|
+
// Queue of bundles to execute once they're dep bundles are loaded
|
|
54
|
+
$parcel$global.bq = [];
|
|
55
|
+
|
|
56
|
+
// Register loaded bundle
|
|
57
|
+
$parcel$global.rlb = ${fnExpr(env, ['bundle'], ['$parcel$global.lb.add(bundle);', '$parcel$global.pq();'])}
|
|
58
|
+
|
|
59
|
+
// Run when ready
|
|
60
|
+
$parcel$global.rwr = ${fnExpr(env,
|
|
61
|
+
// b = bundle public id
|
|
62
|
+
// r = run function to execute the bundle entry
|
|
63
|
+
// d = list of dependent bundles this bundle requires before executing
|
|
64
|
+
['b', 'r', 'd'], ['$parcel$global.bq.push({b, r, d});', '$parcel$global.pq();'])}
|
|
65
|
+
|
|
66
|
+
// Process queue
|
|
67
|
+
$parcel$global.pq = ${fnExpr(env, [], [`var runnableEntry = $parcel$global.bq.find(${fnExpr(env, ['i'], [`return i.d.every(${fnExpr(env, ['dep'], ['return $parcel$global.lb.has(dep);'])});`])});`, 'if (runnableEntry) {', `$parcel$global.bq = $parcel$global.bq.filter(${fnExpr(env, ['i'], ['return i.b !== runnableEntry.b;'])});`, 'runnableEntry.r();', '$parcel$global.pq();', '}'])}
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
70
|
+
exports.bundleQueuePrelude = bundleQueuePrelude;
|
|
71
|
+
const $parcel$export = `
|
|
72
|
+
function $parcel$export(e, n, v, s) {
|
|
73
|
+
Object.defineProperty(e, n, {get: v, set: s, enumerable: true, configurable: true});
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
const $parcel$exportWildcard = `
|
|
77
|
+
function $parcel$exportWildcard(dest, source) {
|
|
78
|
+
Object.keys(source).forEach(function(key) {
|
|
79
|
+
if (key === 'default' || key === '__esModule' || Object.prototype.hasOwnProperty.call(dest, key)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
Object.defineProperty(dest, key, {
|
|
84
|
+
enumerable: true,
|
|
85
|
+
get: function get() {
|
|
86
|
+
return source[key];
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
return dest;
|
|
92
|
+
}
|
|
93
|
+
`;
|
|
94
|
+
const $parcel$interopDefault = `
|
|
95
|
+
function $parcel$interopDefault(a) {
|
|
96
|
+
return a && a.__esModule ? a.default : a;
|
|
97
|
+
}
|
|
98
|
+
`;
|
|
99
|
+
const $parcel$global = env => {
|
|
100
|
+
if (env.supports('global-this')) {
|
|
101
|
+
return `
|
|
102
|
+
var $parcel$global = globalThis;
|
|
103
|
+
`;
|
|
104
|
+
}
|
|
105
|
+
return `
|
|
106
|
+
var $parcel$global =
|
|
107
|
+
typeof globalThis !== 'undefined'
|
|
108
|
+
? globalThis
|
|
109
|
+
: typeof self !== 'undefined'
|
|
110
|
+
? self
|
|
111
|
+
: typeof window !== 'undefined'
|
|
112
|
+
? window
|
|
113
|
+
: typeof global !== 'undefined'
|
|
114
|
+
? global
|
|
115
|
+
: {};
|
|
116
|
+
`;
|
|
117
|
+
};
|
|
118
|
+
const $parcel$defineInteropFlag = `
|
|
119
|
+
function $parcel$defineInteropFlag(a) {
|
|
120
|
+
Object.defineProperty(a, '__esModule', {value: true, configurable: true});
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
const helpers = exports.helpers = {
|
|
124
|
+
$parcel$export,
|
|
125
|
+
$parcel$exportWildcard,
|
|
126
|
+
$parcel$interopDefault,
|
|
127
|
+
$parcel$global,
|
|
128
|
+
$parcel$defineInteropFlag
|
|
129
|
+
};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
function _plugin() {
|
|
8
|
+
const data = require("@atlaspack/plugin");
|
|
9
|
+
_plugin = function () {
|
|
10
|
+
return data;
|
|
11
|
+
};
|
|
12
|
+
return data;
|
|
13
|
+
}
|
|
14
|
+
function _utils() {
|
|
15
|
+
const data = require("@atlaspack/utils");
|
|
16
|
+
_utils = function () {
|
|
17
|
+
return data;
|
|
18
|
+
};
|
|
19
|
+
return data;
|
|
20
|
+
}
|
|
21
|
+
function _diagnostic() {
|
|
22
|
+
const data = require("@atlaspack/diagnostic");
|
|
23
|
+
_diagnostic = function () {
|
|
24
|
+
return data;
|
|
25
|
+
};
|
|
26
|
+
return data;
|
|
27
|
+
}
|
|
28
|
+
function _rust() {
|
|
29
|
+
const data = require("@atlaspack/rust");
|
|
30
|
+
_rust = function () {
|
|
31
|
+
return data;
|
|
32
|
+
};
|
|
33
|
+
return data;
|
|
34
|
+
}
|
|
35
|
+
function _nullthrows() {
|
|
36
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
37
|
+
_nullthrows = function () {
|
|
38
|
+
return data;
|
|
39
|
+
};
|
|
40
|
+
return data;
|
|
41
|
+
}
|
|
42
|
+
var _DevPackager = require("./DevPackager");
|
|
43
|
+
var _ScopeHoistingPackager = require("./ScopeHoistingPackager");
|
|
44
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
45
|
+
const CONFIG_SCHEMA = {
|
|
46
|
+
type: 'object',
|
|
47
|
+
properties: {
|
|
48
|
+
unstable_asyncBundleRuntime: {
|
|
49
|
+
type: 'boolean'
|
|
50
|
+
},
|
|
51
|
+
unstable_forceSkipWrapAssets: {
|
|
52
|
+
type: 'array',
|
|
53
|
+
items: {
|
|
54
|
+
type: 'string'
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
additionalProperties: false
|
|
59
|
+
};
|
|
60
|
+
var _default = exports.default = new (_plugin().Packager)({
|
|
61
|
+
async loadConfig({
|
|
62
|
+
config,
|
|
63
|
+
options
|
|
64
|
+
}) {
|
|
65
|
+
var _conf$contents, _conf$contents2;
|
|
66
|
+
let packageKey = '@atlaspack/packager-js';
|
|
67
|
+
let conf = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
68
|
+
packageKey
|
|
69
|
+
});
|
|
70
|
+
if (conf !== null && conf !== void 0 && conf.contents) {
|
|
71
|
+
_utils().validateSchema.diagnostic(CONFIG_SCHEMA, {
|
|
72
|
+
data: conf === null || conf === void 0 ? void 0 : conf.contents,
|
|
73
|
+
source: await options.inputFS.readFile(conf.filePath, 'utf8'),
|
|
74
|
+
filePath: conf.filePath,
|
|
75
|
+
prependKey: `/${(0, _diagnostic().encodeJSONKeyComponent)(packageKey)}`
|
|
76
|
+
}, packageKey, `Invalid config for ${packageKey}`);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Generate a name for the global parcelRequire function that is unique to this project.
|
|
80
|
+
// This allows multiple parcel builds to coexist on the same page.
|
|
81
|
+
let packageName = await config.getConfigFrom(options.projectRoot + '/index', [], {
|
|
82
|
+
packageKey: 'name'
|
|
83
|
+
});
|
|
84
|
+
let name = (packageName === null || packageName === void 0 ? void 0 : packageName.contents) ?? '';
|
|
85
|
+
return {
|
|
86
|
+
parcelRequireName: 'parcelRequire' + (0, _rust().hashString)(name).slice(-4),
|
|
87
|
+
unstable_asyncBundleRuntime: Boolean(conf === null || conf === void 0 || (_conf$contents = conf.contents) === null || _conf$contents === void 0 ? void 0 : _conf$contents.unstable_asyncBundleRuntime),
|
|
88
|
+
unstable_forceSkipWrapAssets: (conf === null || conf === void 0 || (_conf$contents2 = conf.contents) === null || _conf$contents2 === void 0 ? void 0 : _conf$contents2.unstable_forceSkipWrapAssets) ?? []
|
|
89
|
+
};
|
|
90
|
+
},
|
|
91
|
+
async package({
|
|
92
|
+
bundle,
|
|
93
|
+
bundleGraph,
|
|
94
|
+
getInlineBundleContents,
|
|
95
|
+
getSourceMapReference,
|
|
96
|
+
config,
|
|
97
|
+
options,
|
|
98
|
+
logger
|
|
99
|
+
}) {
|
|
100
|
+
// If this is a non-module script, and there is only one asset with no dependencies,
|
|
101
|
+
// then we don't need to package at all and can pass through the original code un-wrapped.
|
|
102
|
+
let contents, map;
|
|
103
|
+
if (bundle.env.sourceType === 'script') {
|
|
104
|
+
let entries = bundle.getEntryAssets();
|
|
105
|
+
if (entries.length === 1 && bundleGraph.getDependencies(entries[0]).length === 0) {
|
|
106
|
+
contents = await entries[0].getCode();
|
|
107
|
+
map = await entries[0].getMap();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (contents == null) {
|
|
111
|
+
let packager = bundle.env.shouldScopeHoist ? new _ScopeHoistingPackager.ScopeHoistingPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName, (0, _nullthrows().default)(config).unstable_asyncBundleRuntime, (0, _nullthrows().default)(config).unstable_forceSkipWrapAssets, logger) : new _DevPackager.DevPackager(options, bundleGraph, bundle, (0, _nullthrows().default)(config).parcelRequireName);
|
|
112
|
+
({
|
|
113
|
+
contents,
|
|
114
|
+
map
|
|
115
|
+
} = await packager.package());
|
|
116
|
+
}
|
|
117
|
+
contents += '\n' + (await getSourceMapSuffix(getSourceMapReference, map));
|
|
118
|
+
|
|
119
|
+
// For library builds, we need to replace URL references with their final resolved paths.
|
|
120
|
+
// For non-library builds, this is handled in the JS runtime.
|
|
121
|
+
if (bundle.env.isLibrary) {
|
|
122
|
+
({
|
|
123
|
+
contents,
|
|
124
|
+
map
|
|
125
|
+
} = (0, _utils().replaceURLReferences)({
|
|
126
|
+
bundle,
|
|
127
|
+
bundleGraph,
|
|
128
|
+
contents,
|
|
129
|
+
map,
|
|
130
|
+
getReplacement: s => JSON.stringify(s).slice(1, -1)
|
|
131
|
+
}));
|
|
132
|
+
}
|
|
133
|
+
return (0, _utils().replaceInlineReferences)({
|
|
134
|
+
bundle,
|
|
135
|
+
bundleGraph,
|
|
136
|
+
contents,
|
|
137
|
+
getInlineReplacement: (dependency, inlineType, content) => ({
|
|
138
|
+
from: `"${dependency.id}"`,
|
|
139
|
+
to: inlineType === 'string' ? JSON.stringify(content) : content
|
|
140
|
+
}),
|
|
141
|
+
getInlineBundleContents,
|
|
142
|
+
map
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
async function getSourceMapSuffix(getSourceMapReference, map) {
|
|
147
|
+
let sourcemapReference = await getSourceMapReference(map);
|
|
148
|
+
if (sourcemapReference != null) {
|
|
149
|
+
return '//# sourceMappingURL=' + sourcemapReference + '\n';
|
|
150
|
+
} else {
|
|
151
|
+
return '';
|
|
152
|
+
}
|
|
153
|
+
}
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.getSpecifier = getSpecifier;
|
|
7
|
+
exports.isValidIdentifier = isValidIdentifier;
|
|
8
|
+
exports.makeValidIdentifier = makeValidIdentifier;
|
|
9
|
+
exports.replaceScriptDependencies = replaceScriptDependencies;
|
|
10
|
+
function _nullthrows() {
|
|
11
|
+
const data = _interopRequireDefault(require("nullthrows"));
|
|
12
|
+
_nullthrows = function () {
|
|
13
|
+
return data;
|
|
14
|
+
};
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
18
|
+
// This replaces __parcel__require__ references left by the transformer with
|
|
19
|
+
// parcelRequire calls of the resolved asset id. This lets runtimes work within
|
|
20
|
+
// script bundles, which must be outside the bundle wrapper so their variables are global.
|
|
21
|
+
function replaceScriptDependencies(bundleGraph, bundle, code, map, parcelRequireName) {
|
|
22
|
+
let entry = (0, _nullthrows().default)(bundle.getMainEntry());
|
|
23
|
+
let dependencies = bundleGraph.getDependencies(entry);
|
|
24
|
+
let lineCount = 0;
|
|
25
|
+
let offset = 0;
|
|
26
|
+
let columnStartIndex = 0;
|
|
27
|
+
code = code.replace(/\n|__parcel__require__\(['"](.*?)['"]\)/g, (m, s, i) => {
|
|
28
|
+
if (m === '\n') {
|
|
29
|
+
columnStartIndex = i + offset + 1;
|
|
30
|
+
lineCount++;
|
|
31
|
+
return '\n';
|
|
32
|
+
}
|
|
33
|
+
let dep = (0, _nullthrows().default)(dependencies.find(d => getSpecifier(d) === s));
|
|
34
|
+
let resolved = (0, _nullthrows().default)(bundleGraph.getResolvedAsset(dep, bundle));
|
|
35
|
+
let publicId = bundleGraph.getAssetPublicId(resolved);
|
|
36
|
+
let replacement = `${parcelRequireName}("${publicId}")`;
|
|
37
|
+
if (map) {
|
|
38
|
+
let lengthDifference = replacement.length - m.length;
|
|
39
|
+
if (lengthDifference !== 0) {
|
|
40
|
+
map.offsetColumns(lineCount + 1, i + offset - columnStartIndex + m.length, lengthDifference);
|
|
41
|
+
offset += lengthDifference;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return replacement;
|
|
45
|
+
});
|
|
46
|
+
return code;
|
|
47
|
+
}
|
|
48
|
+
function getSpecifier(dep) {
|
|
49
|
+
if (typeof dep.meta.placeholder === 'string') {
|
|
50
|
+
return dep.meta.placeholder;
|
|
51
|
+
}
|
|
52
|
+
return dep.specifier;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// https://262.ecma-international.org/6.0/#sec-names-and-keywords
|
|
56
|
+
const IDENTIFIER_RE = /^[$_\p{ID_Start}][$_\u200C\u200D\p{ID_Continue}]*$/u;
|
|
57
|
+
const ID_START_RE = /^[$_\p{ID_Start}]/u;
|
|
58
|
+
const NON_ID_CONTINUE_RE = /[^$_\u200C\u200D\p{ID_Continue}]/gu;
|
|
59
|
+
function isValidIdentifier(id) {
|
|
60
|
+
return IDENTIFIER_RE.test(id);
|
|
61
|
+
}
|
|
62
|
+
function makeValidIdentifier(name) {
|
|
63
|
+
name = name.replace(NON_ID_CONTINUE_RE, '');
|
|
64
|
+
if (!ID_START_RE.test(name)) {
|
|
65
|
+
name = '_' + name;
|
|
66
|
+
}
|
|
67
|
+
return name;
|
|
68
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/packager-js",
|
|
3
|
-
"version": "2.14.
|
|
3
|
+
"version": "2.14.1-canary.6+57e29c592",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -12,19 +12,20 @@
|
|
|
12
12
|
"main": "lib/index.js",
|
|
13
13
|
"source": "src/index.js",
|
|
14
14
|
"engines": {
|
|
15
|
-
"atlaspack": "
|
|
15
|
+
"atlaspack": "2.14.1-canary.6+57e29c592",
|
|
16
16
|
"node": ">= 16.0.0"
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@atlaspack/diagnostic": "2.14.
|
|
20
|
-
"@atlaspack/feature-flags": "2.14.
|
|
21
|
-
"@atlaspack/plugin": "2.14.
|
|
22
|
-
"@atlaspack/rust": "3.0.
|
|
19
|
+
"@atlaspack/diagnostic": "2.14.1-canary.6+57e29c592",
|
|
20
|
+
"@atlaspack/feature-flags": "2.14.1-canary.6+57e29c592",
|
|
21
|
+
"@atlaspack/plugin": "2.14.1-canary.6+57e29c592",
|
|
22
|
+
"@atlaspack/rust": "3.0.1-canary.6+57e29c592",
|
|
23
|
+
"@atlaspack/types": "2.14.1-canary.6+57e29c592",
|
|
24
|
+
"@atlaspack/utils": "2.14.1-canary.6+57e29c592",
|
|
23
25
|
"@parcel/source-map": "^2.1.1",
|
|
24
|
-
"@atlaspack/types": "2.14.0",
|
|
25
|
-
"@atlaspack/utils": "2.14.0",
|
|
26
26
|
"globals": "^13.2.0",
|
|
27
27
|
"nullthrows": "^1.1.1"
|
|
28
28
|
},
|
|
29
|
-
"type": "commonjs"
|
|
29
|
+
"type": "commonjs",
|
|
30
|
+
"gitHead": "57e29c592cff406d084b3c676a1c899f0bb6e78f"
|
|
30
31
|
}
|