@atlaspack/package-manager 2.14.18-noselfbuild-3f2849b52.0 → 2.14.18-noselfbuild-342bd6c75.0

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.
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ function _logger() {
8
+ const data = _interopRequireDefault(require("@atlaspack/logger"));
9
+ _logger = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _stream() {
15
+ const data = require("stream");
16
+ _stream = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
22
+ // Transforms chunks of json strings to parsed objects.
23
+ // Pair with split2 to parse stream of newline-delimited text.
24
+ class JSONParseStream extends _stream().Transform {
25
+ constructor(options) {
26
+ super({
27
+ ...options,
28
+ objectMode: true
29
+ });
30
+ }
31
+
32
+ // $FlowFixMe We are in object mode, so we emit objects, not strings
33
+ _transform(chunk, encoding, callback) {
34
+ try {
35
+ let parsed;
36
+ try {
37
+ parsed = JSON.parse(chunk.toString());
38
+ } catch (e) {
39
+ // Be permissive and ignoreJSON parse errors in case there was
40
+ // a non-JSON line in the package manager's stdout.
41
+ _logger().default.verbose({
42
+ message: 'Ignored invalid JSON message: ' + chunk.toString(),
43
+ origin: '@atlaspack/package-manager'
44
+ });
45
+ return;
46
+ }
47
+ callback(null, parsed);
48
+ } catch (err) {
49
+ callback(err);
50
+ }
51
+ }
52
+ }
53
+ exports.default = JSONParseStream;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.MockPackageInstaller = void 0;
7
+ function _path() {
8
+ const data = _interopRequireDefault(require("path"));
9
+ _path = function () {
10
+ return data;
11
+ };
12
+ return data;
13
+ }
14
+ function _buildCache() {
15
+ const data = require("@atlaspack/build-cache");
16
+ _buildCache = function () {
17
+ return data;
18
+ };
19
+ return data;
20
+ }
21
+ function _fs() {
22
+ const data = require("@atlaspack/fs");
23
+ _fs = function () {
24
+ return data;
25
+ };
26
+ return data;
27
+ }
28
+ var _package = _interopRequireDefault(require("../package.json"));
29
+ var _utils = require("./utils");
30
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
+ // This PackageInstaller implementation simply copies files from one filesystem to another.
32
+ // Mostly useful for testing purposes.
33
+ class MockPackageInstaller {
34
+ packages = new Map();
35
+ register(packageName, fs, packagePath) {
36
+ this.packages.set(packageName, {
37
+ fs,
38
+ packagePath
39
+ });
40
+ }
41
+ async install({
42
+ modules,
43
+ fs,
44
+ cwd,
45
+ packagePath,
46
+ saveDev = true
47
+ }) {
48
+ if (packagePath == null) {
49
+ packagePath = _path().default.join(cwd, 'package.json');
50
+ await fs.writeFile(packagePath, '{}');
51
+ }
52
+ let pkg = JSON.parse(await fs.readFile(packagePath, 'utf8'));
53
+ let key = saveDev ? 'devDependencies' : 'dependencies';
54
+ if (!pkg[key]) {
55
+ pkg[key] = {};
56
+ }
57
+ for (let module of modules) {
58
+ pkg[key][module.name] = '^' + (await this.installPackage(module, fs, packagePath));
59
+ }
60
+ await fs.writeFile(packagePath, JSON.stringify(pkg));
61
+ }
62
+ async installPackage(moduleRequest, fs, packagePath) {
63
+ let pkg = this.packages.get(moduleRequest.name);
64
+ if (!pkg) {
65
+ throw new Error('Unknown package ' + moduleRequest.name);
66
+ }
67
+ let dest = _path().default.join(_path().default.dirname(packagePath), 'node_modules', moduleRequest.name);
68
+ await (0, _fs().ncp)(pkg.fs, pkg.packagePath, fs, dest);
69
+ let packageJSON = JSON.parse(await fs.readFile(_path().default.join(dest, 'package.json'), 'utf8'));
70
+ if (packageJSON.dependencies != null) {
71
+ for (let dep of (0, _utils.moduleRequestsFromDependencyMap)(packageJSON.dependencies)) {
72
+ await this.installPackage(dep, fs, packagePath);
73
+ }
74
+ }
75
+ return packageJSON.version;
76
+ }
77
+ }
78
+ exports.MockPackageInstaller = MockPackageInstaller;
79
+ (0, _buildCache().registerSerializableClass)(`${_package.default.version}:MockPackageInstaller`, MockPackageInstaller);