1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 | var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
6 | if (k2 === undefined) k2 = k;
|
7 | Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
8 | }) : (function(o, m, k, k2) {
|
9 | if (k2 === undefined) k2 = k;
|
10 | o[k2] = m[k];
|
11 | }));
|
12 | var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
13 | Object.defineProperty(o, "default", { enumerable: true, value: v });
|
14 | }) : function(o, v) {
|
15 | o["default"] = v;
|
16 | });
|
17 | var __importStar = (this && this.__importStar) || function (mod) {
|
18 | if (mod && mod.__esModule) return mod;
|
19 | var result = {};
|
20 | if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
21 | __setModuleDefault(result, mod);
|
22 | return result;
|
23 | };
|
24 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
25 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
26 | };
|
27 | Object.defineProperty(exports, "__esModule", { value: true });
|
28 | exports.copyStaticFiles = exports.defaultCopyStaticFiles = exports.validateNpmPackageName = exports.getTargetDir = exports.npmVersion = void 0;
|
29 | const cross_spawn_extra_1 = __importDefault(require("cross-spawn-extra"));
|
30 | const json5_1 = __importDefault(require("json5"));
|
31 | const validate_npm_package_name_1 = __importDefault(require("validate-npm-package-name"));
|
32 | const fs_extra_1 = require("fs-extra");
|
33 | const path_1 = require("path");
|
34 | const static_file_1 = __importStar(require("@yarn-tool/static-file"));
|
35 | Object.defineProperty(exports, "defaultCopyStaticFiles", { enumerable: true, get: function () { return static_file_1.defaultCopyStaticFiles; } });
|
36 | const searchWorkspacePrefixByName_1 = __importDefault(require("./searchWorkspacePrefixByName"));
|
37 | function npmVersion(npmClient, cwd) {
|
38 | let args = [
|
39 | 'version',
|
40 | ];
|
41 | npmClient = npmClient || 'npm';
|
42 | if (npmClient === 'yarn') {
|
43 | args = [
|
44 | 'versions',
|
45 | ];
|
46 | }
|
47 | let cp = cross_spawn_extra_1.default.sync(npmClient, args, {
|
48 | cwd,
|
49 | stripAnsi: true,
|
50 | });
|
51 | if (cp.error) {
|
52 | throw cp.error;
|
53 | }
|
54 | let output = cp.stdout.toString()
|
55 | .replace(/^yarn versions [^\n]+$/gm, '')
|
56 | .replace(/^Done in [^\n]+$/gm, '')
|
57 | .replace(/^\s+|\s+$/g, '');
|
58 | let json = json5_1.default.parse(output);
|
59 | return json;
|
60 | }
|
61 | exports.npmVersion = npmVersion;
|
62 | function getTargetDir(options) {
|
63 | var _a;
|
64 | let targetDir;
|
65 | let targetName = options.targetName || null;
|
66 | let { inputName, cwd, hasWorkspace, workspacePrefix, workspacesConfig } = options;
|
67 | if (hasWorkspace && !((_a = workspacesConfig === null || workspacesConfig === void 0 ? void 0 : workspacesConfig.prefix) === null || _a === void 0 ? void 0 : _a.length)) {
|
68 | throw new RangeError(`can't found workspace prefix`);
|
69 | }
|
70 | if (targetName) {
|
71 | validateNpmPackageName(targetName, true);
|
72 | }
|
73 | if (inputName) {
|
74 | targetName = targetName || inputName;
|
75 | let ret = validateNpmPackageName(inputName, true);
|
76 | let name = inputName;
|
77 | let basePath;
|
78 | if (hasWorkspace) {
|
79 | const workspacePrefix = searchWorkspacePrefixByName_1.default({
|
80 | inputName,
|
81 | workspacesConfig,
|
82 | });
|
83 | basePath = path_1.join(hasWorkspace, workspacePrefix);
|
84 | }
|
85 | else {
|
86 | basePath = cwd;
|
87 | }
|
88 | if (ret.scopedPackagePattern) {
|
89 | name = name
|
90 | .replace(/[\/\\]+/g, '_')
|
91 | .replace(/^@/g, '');
|
92 | if (!fs_extra_1.pathExistsSync(path_1.join(basePath, ret.subname))) {
|
93 | name = ret.subname;
|
94 | }
|
95 | }
|
96 | targetDir = path_1.resolve(basePath, name);
|
97 | }
|
98 | else {
|
99 | targetDir = cwd;
|
100 | }
|
101 | return {
|
102 | targetDir,
|
103 | targetName,
|
104 | cwd,
|
105 | };
|
106 | }
|
107 | exports.getTargetDir = getTargetDir;
|
108 | const scopedPackagePattern = new RegExp('^(?:@([^/]+?)[/])?([^/]+?)$');
|
109 | function validateNpmPackageName(name, throwErr) {
|
110 | let ret = validate_npm_package_name_1.default(name);
|
111 | ret.name = name;
|
112 | if (!ret.errors || !ret.errors.length) {
|
113 | const nameMatch = name.match(scopedPackagePattern);
|
114 | if (nameMatch) {
|
115 | ret.scopedPackagePattern = true;
|
116 | ret.user = nameMatch[1];
|
117 | ret.subname = nameMatch[2];
|
118 | }
|
119 | else {
|
120 | ret.scopedPackagePattern = false;
|
121 | }
|
122 | }
|
123 | else if (throwErr) {
|
124 | throw new RangeError(ret.errors.concat(ret.warnings || []).join(' ; '));
|
125 | }
|
126 | return ret;
|
127 | }
|
128 | exports.validateNpmPackageName = validateNpmPackageName;
|
129 | function copyStaticFiles(file_map, options) {
|
130 | return static_file_1.default({
|
131 | ...options,
|
132 | file_map,
|
133 | });
|
134 | }
|
135 | exports.copyStaticFiles = copyStaticFiles;
|
136 |
|
\ | No newline at end of file |