@rushstack/package-extractor 0.1.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.
- package/LICENSE +24 -0
- package/README.md +12 -0
- package/dist/package-extractor.d.ts +149 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/lib/ArchiveManager.d.ts +14 -0
- package/lib/ArchiveManager.d.ts.map +1 -0
- package/lib/ArchiveManager.js +64 -0
- package/lib/ArchiveManager.js.map +1 -0
- package/lib/PackageExtractor.d.ts +174 -0
- package/lib/PackageExtractor.d.ts.map +1 -0
- package/lib/PackageExtractor.js +576 -0
- package/lib/PackageExtractor.js.map +1 -0
- package/lib/PathConstants.d.ts +4 -0
- package/lib/PathConstants.d.ts.map +1 -0
- package/lib/PathConstants.js +7 -0
- package/lib/PathConstants.js.map +1 -0
- package/lib/SymlinkAnalyzer.d.ts +58 -0
- package/lib/SymlinkAnalyzer.d.ts.map +1 -0
- package/lib/SymlinkAnalyzer.js +140 -0
- package/lib/SymlinkAnalyzer.js.map +1 -0
- package/lib/Utils.d.ts +2 -0
- package/lib/Utils.d.ts.map +1 -0
- package/lib/Utils.js +20 -0
- package/lib/Utils.js.map +1 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +8 -0
- package/lib/index.js.map +1 -0
- package/lib/scripts/create-links.d.ts +2 -0
- package/lib/scripts/create-links.d.ts.map +1 -0
- package/lib/scripts/create-links.js +143 -0
- package/lib/scripts/create-links.js.map +1 -0
- package/package.json +37 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
@rushstack/package-extractor
|
|
2
|
+
|
|
3
|
+
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
4
|
+
|
|
5
|
+
MIT License
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
8
|
+
a copy of this software and associated documentation files (the
|
|
9
|
+
"Software"), to deal in the Software without restriction, including
|
|
10
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
11
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
12
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
13
|
+
the following conditions:
|
|
14
|
+
|
|
15
|
+
The above copyright notice and this permission notice shall be
|
|
16
|
+
included in all copies or substantial portions of the Software.
|
|
17
|
+
|
|
18
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
19
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
20
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
21
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
22
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
23
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
24
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
## @rushstack/package-extractor
|
|
2
|
+
|
|
3
|
+
A library used for creating an isolated copy of a package and, optionally, bundling it into an archive.
|
|
4
|
+
|
|
5
|
+
## Links
|
|
6
|
+
|
|
7
|
+
- [CHANGELOG.md](
|
|
8
|
+
https://github.com/microsoft/rushstack/blob/main/libraries/deploy-manager/CHANGELOG.md) - Find
|
|
9
|
+
out what's new in the latest version
|
|
10
|
+
- [API Reference](https://rushstack.io/pages/api/deploy-manager/)
|
|
11
|
+
|
|
12
|
+
`@rushstack/package-extractor` is part of the [Rush Stack](https://rushstack.io/) family of projects.
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { IPackageJson } from '@rushstack/node-core-library';
|
|
2
|
+
import { ITerminal } from '@rushstack/node-core-library';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Options that can be provided to the extractor.
|
|
6
|
+
*
|
|
7
|
+
* @public
|
|
8
|
+
*/
|
|
9
|
+
export declare interface IExtractorOptions {
|
|
10
|
+
/**
|
|
11
|
+
* A terminal to log extraction progress.
|
|
12
|
+
*/
|
|
13
|
+
terminal: ITerminal;
|
|
14
|
+
/**
|
|
15
|
+
* The main project to include in the extraction operation.
|
|
16
|
+
*/
|
|
17
|
+
mainProjectName: string;
|
|
18
|
+
/**
|
|
19
|
+
* The source folder that copying originates from. Generally it is the repo root folder.
|
|
20
|
+
*/
|
|
21
|
+
sourceRootFolder: string;
|
|
22
|
+
/**
|
|
23
|
+
* The target folder for the extraction.
|
|
24
|
+
*/
|
|
25
|
+
targetRootFolder: string;
|
|
26
|
+
/**
|
|
27
|
+
* Whether to overwrite the target folder if it already exists.
|
|
28
|
+
*/
|
|
29
|
+
overwriteExisting: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* The desired path to be used when archiving the target folder. Supported file extensions: .zip.
|
|
32
|
+
*/
|
|
33
|
+
createArchiveFilePath?: string;
|
|
34
|
+
/**
|
|
35
|
+
* Whether to skip copying files to the extraction target directory, and only create an extraction
|
|
36
|
+
* archive. This is only supported when linkCreation is 'script' or 'none'.
|
|
37
|
+
*/
|
|
38
|
+
createArchiveOnly?: boolean;
|
|
39
|
+
/**
|
|
40
|
+
* The pnpmfile configuration if using PNPM, otherwise undefined. The configuration will be used to
|
|
41
|
+
* transform the package.json prior to extraction.
|
|
42
|
+
*/
|
|
43
|
+
transformPackageJson?: (packageJson: IPackageJson) => IPackageJson | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* If dependencies from the "devDependencies" package.json field should be included in the extraction.
|
|
46
|
+
*/
|
|
47
|
+
includeDevDependencies?: boolean;
|
|
48
|
+
/**
|
|
49
|
+
* If files ignored by the .npmignore file should be included in the extraction.
|
|
50
|
+
*/
|
|
51
|
+
includeNpmIgnoreFiles?: boolean;
|
|
52
|
+
/**
|
|
53
|
+
* The folder where the PNPM "node_modules" folder is located. This is used to resolve packages linked
|
|
54
|
+
* to the PNPM virtual store.
|
|
55
|
+
*/
|
|
56
|
+
pnpmInstallFolder?: string;
|
|
57
|
+
/**
|
|
58
|
+
* The link creation mode to use.
|
|
59
|
+
* "default": Create the links while copying the files; this is the default behavior. Use this setting
|
|
60
|
+
* if your file copy tool can handle links correctly.
|
|
61
|
+
* "script": A Node.js script called create-links.js will be written to the target folder. Use this setting
|
|
62
|
+
* to create links on the server machine, after the files have been uploaded.
|
|
63
|
+
* "none": Do nothing; some other tool may create the links later, based on the extractor-metadata.json file.
|
|
64
|
+
*/
|
|
65
|
+
linkCreation?: 'default' | 'script' | 'none';
|
|
66
|
+
/**
|
|
67
|
+
* An additional folder containing files which will be copied into the root of the extraction.
|
|
68
|
+
*/
|
|
69
|
+
folderToCopy?: string;
|
|
70
|
+
/**
|
|
71
|
+
* Configurations for individual projects, keyed by the project path relative to the sourceRootFolder.
|
|
72
|
+
*/
|
|
73
|
+
projectConfigurations: IExtractorProjectConfiguration[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* The extractor configuration for individual projects.
|
|
78
|
+
*
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
export declare interface IExtractorProjectConfiguration {
|
|
82
|
+
/**
|
|
83
|
+
* The name of the project.
|
|
84
|
+
*/
|
|
85
|
+
projectName: string;
|
|
86
|
+
/**
|
|
87
|
+
* The absolute path to the project.
|
|
88
|
+
*/
|
|
89
|
+
projectFolder: string;
|
|
90
|
+
/**
|
|
91
|
+
* The names of additional projects to include when extracting this project.
|
|
92
|
+
*/
|
|
93
|
+
additionalProjectsToInclude?: string[];
|
|
94
|
+
/**
|
|
95
|
+
* The names of additional dependencies to include when extracting this project.
|
|
96
|
+
*/
|
|
97
|
+
additionalDependenciesToInclude?: string[];
|
|
98
|
+
/**
|
|
99
|
+
* The names of additional dependencies to exclude when extracting this project.
|
|
100
|
+
*/
|
|
101
|
+
dependenciesToExclude?: string[];
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Manages the business logic for the "rush deploy" command.
|
|
106
|
+
*
|
|
107
|
+
* @public
|
|
108
|
+
*/
|
|
109
|
+
export declare class PackageExtractor {
|
|
110
|
+
/**
|
|
111
|
+
* Extract a package using the provided options
|
|
112
|
+
*/
|
|
113
|
+
extractAsync(options: IExtractorOptions): Promise<void>;
|
|
114
|
+
private _performExtractionAsync;
|
|
115
|
+
/**
|
|
116
|
+
* Recursively crawl the node_modules dependencies and collect the result in IExtractorState.foldersToCopy.
|
|
117
|
+
*/
|
|
118
|
+
private _collectFoldersAsync;
|
|
119
|
+
private _applyDependencyFilters;
|
|
120
|
+
/**
|
|
121
|
+
* Maps a file path from IExtractorOptions.sourceRootFolder to IExtractorOptions.targetRootFolder
|
|
122
|
+
*
|
|
123
|
+
* Example input: "C:\\MyRepo\\libraries\\my-lib"
|
|
124
|
+
* Example output: "C:\\MyRepo\\common\\deploy\\libraries\\my-lib"
|
|
125
|
+
*/
|
|
126
|
+
private _remapPathForExtractorFolder;
|
|
127
|
+
/**
|
|
128
|
+
* Maps a file path from IExtractorOptions.sourceRootFolder to relative path
|
|
129
|
+
*
|
|
130
|
+
* Example input: "C:\\MyRepo\\libraries\\my-lib"
|
|
131
|
+
* Example output: "libraries/my-lib"
|
|
132
|
+
*/
|
|
133
|
+
private _remapPathForExtractorMetadata;
|
|
134
|
+
/**
|
|
135
|
+
* Copy one package folder to the extractor target folder.
|
|
136
|
+
*/
|
|
137
|
+
private _extractFolderAsync;
|
|
138
|
+
/**
|
|
139
|
+
* Create a symlink as described by the ILinkInfo object.
|
|
140
|
+
*/
|
|
141
|
+
private _extractSymlinkAsync;
|
|
142
|
+
/**
|
|
143
|
+
* Write the common/deploy/deploy-metadata.json file.
|
|
144
|
+
*/
|
|
145
|
+
private _writeExtractorMetadataAsync;
|
|
146
|
+
private _makeBinLinksAsync;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
export { }
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// This file is read by tools that parse documentation comments conforming to the TSDoc standard.
|
|
2
|
+
// It should be published with your NPM package. It should not be tracked by Git.
|
|
3
|
+
{
|
|
4
|
+
"tsdocVersion": "0.12",
|
|
5
|
+
"toolPackages": [
|
|
6
|
+
{
|
|
7
|
+
"packageName": "@microsoft/api-extractor",
|
|
8
|
+
"packageVersion": "7.34.4"
|
|
9
|
+
}
|
|
10
|
+
]
|
|
11
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { FileSystemStats } from '@rushstack/node-core-library';
|
|
3
|
+
export interface IAddToArchiveOptions {
|
|
4
|
+
filePath?: string;
|
|
5
|
+
fileData?: Buffer | string;
|
|
6
|
+
archivePath: string;
|
|
7
|
+
stats?: FileSystemStats;
|
|
8
|
+
}
|
|
9
|
+
export declare class ArchiveManager {
|
|
10
|
+
private _zip;
|
|
11
|
+
addToArchiveAsync(options: IAddToArchiveOptions): Promise<void>;
|
|
12
|
+
createArchiveAsync(archiveFilePath: string): Promise<void>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=ArchiveManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArchiveManager.d.ts","sourceRoot":"","sources":["../src/ArchiveManager.ts"],"names":[],"mappings":";AAIA,OAAO,EAAc,eAAe,EAAQ,MAAM,8BAA8B,CAAC;AAUjF,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,eAAe,CAAC;CACzB;AAED,qBAAa,cAAc;IACzB,OAAO,CAAC,IAAI,CAAsB;IAErB,iBAAiB,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAAC,IAAI,CAAC;IA+B/D,kBAAkB,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CAOxE"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.
|
|
3
|
+
// See LICENSE in the project root for license information.
|
|
4
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
5
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
6
|
+
};
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.ArchiveManager = void 0;
|
|
9
|
+
const jszip_1 = __importDefault(require("jszip"));
|
|
10
|
+
const node_core_library_1 = require("@rushstack/node-core-library");
|
|
11
|
+
// 755 are default permissions to allow read/write/execute for owner and read/execute for group and others.
|
|
12
|
+
const DEFAULT_FILE_PERMISSIONS = 0o755;
|
|
13
|
+
// This value sets the allowed permissions when preserving symbolic links.
|
|
14
|
+
// 120000 is the symbolic link identifier, and is OR'd with the default file permissions.
|
|
15
|
+
// See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h#n10
|
|
16
|
+
// eslint-disable-next-line no-bitwise
|
|
17
|
+
const SYMBOLIC_LINK_PERMISSIONS = 0o120000 | DEFAULT_FILE_PERMISSIONS;
|
|
18
|
+
class ArchiveManager {
|
|
19
|
+
constructor() {
|
|
20
|
+
this._zip = new jszip_1.default();
|
|
21
|
+
}
|
|
22
|
+
async addToArchiveAsync(options) {
|
|
23
|
+
var _a;
|
|
24
|
+
const { filePath, fileData, archivePath } = options;
|
|
25
|
+
let data;
|
|
26
|
+
let permissions;
|
|
27
|
+
if (filePath) {
|
|
28
|
+
const stats = (_a = options.stats) !== null && _a !== void 0 ? _a : (await node_core_library_1.FileSystem.getLinkStatisticsAsync(filePath));
|
|
29
|
+
if (stats.isSymbolicLink()) {
|
|
30
|
+
data = await node_core_library_1.FileSystem.readLinkAsync(filePath);
|
|
31
|
+
permissions = SYMBOLIC_LINK_PERMISSIONS;
|
|
32
|
+
}
|
|
33
|
+
else if (stats.isDirectory()) {
|
|
34
|
+
throw new Error('Directories cannot be added to the archive');
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
data = await node_core_library_1.FileSystem.readFileToBufferAsync(filePath);
|
|
38
|
+
permissions = stats.mode;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (fileData) {
|
|
42
|
+
data = fileData;
|
|
43
|
+
permissions = DEFAULT_FILE_PERMISSIONS;
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error('Either filePath or fileData must be provided');
|
|
47
|
+
}
|
|
48
|
+
// Replace backslashes for Unix compat
|
|
49
|
+
const addPath = node_core_library_1.Path.convertToSlashes(archivePath);
|
|
50
|
+
this._zip.file(addPath, data, {
|
|
51
|
+
unixPermissions: permissions,
|
|
52
|
+
dir: false
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
async createArchiveAsync(archiveFilePath) {
|
|
56
|
+
const zipContent = await this._zip.generateAsync({
|
|
57
|
+
type: 'nodebuffer',
|
|
58
|
+
platform: 'UNIX'
|
|
59
|
+
});
|
|
60
|
+
await node_core_library_1.FileSystem.writeFileAsync(archiveFilePath, zipContent);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
exports.ArchiveManager = ArchiveManager;
|
|
64
|
+
//# sourceMappingURL=ArchiveManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ArchiveManager.js","sourceRoot":"","sources":["../src/ArchiveManager.ts"],"names":[],"mappings":";AAAA,4FAA4F;AAC5F,2DAA2D;;;;;;AAE3D,kDAA0B;AAC1B,oEAAiF;AAEjF,2GAA2G;AAC3G,MAAM,wBAAwB,GAAW,KAAK,CAAC;AAC/C,0EAA0E;AAC1E,yFAAyF;AACzF,6GAA6G;AAC7G,sCAAsC;AACtC,MAAM,yBAAyB,GA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,CAAC,eAAuB;QACrD,MAAM,UAAU,GAAW,MAAM,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC;YACvD,IAAI,EAAE,YAAY;YAClB,QAAQ,EAAE,MAAM;SACjB,CAAC,CAAC;QACH,MAAM,8BAAU,CAAC,cAAc,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC;IAC/D,CAAC;CACF;AAzCD,wCAyCC","sourcesContent":["// Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT license.\n// See LICENSE in the project root for license information.\n\nimport JSZip from 'jszip';\nimport { FileSystem, FileSystemStats, Path } from '@rushstack/node-core-library';\n\n// 755 are default permissions to allow read/write/execute for owner and read/execute for group and others.\nconst DEFAULT_FILE_PERMISSIONS: number = 0o755;\n// This value sets the allowed permissions when preserving symbolic links.\n// 120000 is the symbolic link identifier, and is OR'd with the default file permissions.\n// See: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/include/uapi/linux/stat.h#n10\n// eslint-disable-next-line no-bitwise\nconst SYMBOLIC_LINK_PERMISSIONS: number = 0o120000 | DEFAULT_FILE_PERMISSIONS;\n\nexport interface IAddToArchiveOptions {\n filePath?: string;\n fileData?: Buffer | string;\n archivePath: string;\n stats?: FileSystemStats;\n}\n\nexport class ArchiveManager {\n private _zip: JSZip = new JSZip();\n\n public async addToArchiveAsync(options: IAddToArchiveOptions): Promise<void> {\n const { filePath, fileData, archivePath } = options;\n\n let data: Buffer | string;\n let permissions: number;\n if (filePath) {\n const stats: FileSystemStats = options.stats ?? (await FileSystem.getLinkStatisticsAsync(filePath));\n if (stats.isSymbolicLink()) {\n data = await FileSystem.readLinkAsync(filePath);\n permissions = SYMBOLIC_LINK_PERMISSIONS;\n } else if (stats.isDirectory()) {\n throw new Error('Directories cannot be added to the archive');\n } else {\n data = await FileSystem.readFileToBufferAsync(filePath);\n permissions = stats.mode;\n }\n } else if (fileData) {\n data = fileData;\n permissions = DEFAULT_FILE_PERMISSIONS;\n } else {\n throw new Error('Either filePath or fileData must be provided');\n }\n\n // Replace backslashes for Unix compat\n const addPath: string = Path.convertToSlashes(archivePath);\n this._zip.file(addPath, data, {\n unixPermissions: permissions,\n dir: false\n });\n }\n\n public async createArchiveAsync(archiveFilePath: string): Promise<void> {\n const zipContent: Buffer = await this._zip.generateAsync({\n type: 'nodebuffer',\n platform: 'UNIX'\n });\n await FileSystem.writeFileAsync(archiveFilePath, zipContent);\n }\n}\n"]}
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { type IPackageJson, type ITerminal } from '@rushstack/node-core-library';
|
|
2
|
+
import { type ILinkInfo } from './SymlinkAnalyzer';
|
|
3
|
+
declare module 'npm-packlist' {
|
|
4
|
+
class Walker {
|
|
5
|
+
readonly result: string[];
|
|
6
|
+
constructor(opts: {
|
|
7
|
+
path: string;
|
|
8
|
+
});
|
|
9
|
+
on(event: 'done', callback: (result: string[]) => void): Walker;
|
|
10
|
+
on(event: 'error', callback: (error: Error) => void): Walker;
|
|
11
|
+
start(): void;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Part of the extractor-matadata.json file format. Represents an extracted project.
|
|
16
|
+
*/
|
|
17
|
+
interface IProjectInfoJson {
|
|
18
|
+
/**
|
|
19
|
+
* This path is relative to the extractor target folder.
|
|
20
|
+
*/
|
|
21
|
+
path: string;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The extractor-metadata.json file format.
|
|
25
|
+
*/
|
|
26
|
+
export interface IExtractorMetadataJson {
|
|
27
|
+
mainProjectName: string;
|
|
28
|
+
projects: IProjectInfoJson[];
|
|
29
|
+
links: ILinkInfo[];
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* The extractor configuration for individual projects.
|
|
33
|
+
*
|
|
34
|
+
* @public
|
|
35
|
+
*/
|
|
36
|
+
export interface IExtractorProjectConfiguration {
|
|
37
|
+
/**
|
|
38
|
+
* The name of the project.
|
|
39
|
+
*/
|
|
40
|
+
projectName: string;
|
|
41
|
+
/**
|
|
42
|
+
* The absolute path to the project.
|
|
43
|
+
*/
|
|
44
|
+
projectFolder: string;
|
|
45
|
+
/**
|
|
46
|
+
* The names of additional projects to include when extracting this project.
|
|
47
|
+
*/
|
|
48
|
+
additionalProjectsToInclude?: string[];
|
|
49
|
+
/**
|
|
50
|
+
* The names of additional dependencies to include when extracting this project.
|
|
51
|
+
*/
|
|
52
|
+
additionalDependenciesToInclude?: string[];
|
|
53
|
+
/**
|
|
54
|
+
* The names of additional dependencies to exclude when extracting this project.
|
|
55
|
+
*/
|
|
56
|
+
dependenciesToExclude?: string[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Options that can be provided to the extractor.
|
|
60
|
+
*
|
|
61
|
+
* @public
|
|
62
|
+
*/
|
|
63
|
+
export interface IExtractorOptions {
|
|
64
|
+
/**
|
|
65
|
+
* A terminal to log extraction progress.
|
|
66
|
+
*/
|
|
67
|
+
terminal: ITerminal;
|
|
68
|
+
/**
|
|
69
|
+
* The main project to include in the extraction operation.
|
|
70
|
+
*/
|
|
71
|
+
mainProjectName: string;
|
|
72
|
+
/**
|
|
73
|
+
* The source folder that copying originates from. Generally it is the repo root folder.
|
|
74
|
+
*/
|
|
75
|
+
sourceRootFolder: string;
|
|
76
|
+
/**
|
|
77
|
+
* The target folder for the extraction.
|
|
78
|
+
*/
|
|
79
|
+
targetRootFolder: string;
|
|
80
|
+
/**
|
|
81
|
+
* Whether to overwrite the target folder if it already exists.
|
|
82
|
+
*/
|
|
83
|
+
overwriteExisting: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* The desired path to be used when archiving the target folder. Supported file extensions: .zip.
|
|
86
|
+
*/
|
|
87
|
+
createArchiveFilePath?: string;
|
|
88
|
+
/**
|
|
89
|
+
* Whether to skip copying files to the extraction target directory, and only create an extraction
|
|
90
|
+
* archive. This is only supported when linkCreation is 'script' or 'none'.
|
|
91
|
+
*/
|
|
92
|
+
createArchiveOnly?: boolean;
|
|
93
|
+
/**
|
|
94
|
+
* The pnpmfile configuration if using PNPM, otherwise undefined. The configuration will be used to
|
|
95
|
+
* transform the package.json prior to extraction.
|
|
96
|
+
*/
|
|
97
|
+
transformPackageJson?: (packageJson: IPackageJson) => IPackageJson | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* If dependencies from the "devDependencies" package.json field should be included in the extraction.
|
|
100
|
+
*/
|
|
101
|
+
includeDevDependencies?: boolean;
|
|
102
|
+
/**
|
|
103
|
+
* If files ignored by the .npmignore file should be included in the extraction.
|
|
104
|
+
*/
|
|
105
|
+
includeNpmIgnoreFiles?: boolean;
|
|
106
|
+
/**
|
|
107
|
+
* The folder where the PNPM "node_modules" folder is located. This is used to resolve packages linked
|
|
108
|
+
* to the PNPM virtual store.
|
|
109
|
+
*/
|
|
110
|
+
pnpmInstallFolder?: string;
|
|
111
|
+
/**
|
|
112
|
+
* The link creation mode to use.
|
|
113
|
+
* "default": Create the links while copying the files; this is the default behavior. Use this setting
|
|
114
|
+
* if your file copy tool can handle links correctly.
|
|
115
|
+
* "script": A Node.js script called create-links.js will be written to the target folder. Use this setting
|
|
116
|
+
* to create links on the server machine, after the files have been uploaded.
|
|
117
|
+
* "none": Do nothing; some other tool may create the links later, based on the extractor-metadata.json file.
|
|
118
|
+
*/
|
|
119
|
+
linkCreation?: 'default' | 'script' | 'none';
|
|
120
|
+
/**
|
|
121
|
+
* An additional folder containing files which will be copied into the root of the extraction.
|
|
122
|
+
*/
|
|
123
|
+
folderToCopy?: string;
|
|
124
|
+
/**
|
|
125
|
+
* Configurations for individual projects, keyed by the project path relative to the sourceRootFolder.
|
|
126
|
+
*/
|
|
127
|
+
projectConfigurations: IExtractorProjectConfiguration[];
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Manages the business logic for the "rush deploy" command.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
export declare class PackageExtractor {
|
|
135
|
+
/**
|
|
136
|
+
* Extract a package using the provided options
|
|
137
|
+
*/
|
|
138
|
+
extractAsync(options: IExtractorOptions): Promise<void>;
|
|
139
|
+
private _performExtractionAsync;
|
|
140
|
+
/**
|
|
141
|
+
* Recursively crawl the node_modules dependencies and collect the result in IExtractorState.foldersToCopy.
|
|
142
|
+
*/
|
|
143
|
+
private _collectFoldersAsync;
|
|
144
|
+
private _applyDependencyFilters;
|
|
145
|
+
/**
|
|
146
|
+
* Maps a file path from IExtractorOptions.sourceRootFolder to IExtractorOptions.targetRootFolder
|
|
147
|
+
*
|
|
148
|
+
* Example input: "C:\\MyRepo\\libraries\\my-lib"
|
|
149
|
+
* Example output: "C:\\MyRepo\\common\\deploy\\libraries\\my-lib"
|
|
150
|
+
*/
|
|
151
|
+
private _remapPathForExtractorFolder;
|
|
152
|
+
/**
|
|
153
|
+
* Maps a file path from IExtractorOptions.sourceRootFolder to relative path
|
|
154
|
+
*
|
|
155
|
+
* Example input: "C:\\MyRepo\\libraries\\my-lib"
|
|
156
|
+
* Example output: "libraries/my-lib"
|
|
157
|
+
*/
|
|
158
|
+
private _remapPathForExtractorMetadata;
|
|
159
|
+
/**
|
|
160
|
+
* Copy one package folder to the extractor target folder.
|
|
161
|
+
*/
|
|
162
|
+
private _extractFolderAsync;
|
|
163
|
+
/**
|
|
164
|
+
* Create a symlink as described by the ILinkInfo object.
|
|
165
|
+
*/
|
|
166
|
+
private _extractSymlinkAsync;
|
|
167
|
+
/**
|
|
168
|
+
* Write the common/deploy/deploy-metadata.json file.
|
|
169
|
+
*/
|
|
170
|
+
private _writeExtractorMetadataAsync;
|
|
171
|
+
private _makeBinLinksAsync;
|
|
172
|
+
}
|
|
173
|
+
export {};
|
|
174
|
+
//# sourceMappingURL=PackageExtractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PackageExtractor.d.ts","sourceRoot":"","sources":["../src/PackageExtractor.ts"],"names":[],"mappings":"AAQA,OAAO,EASL,KAAK,YAAY,EACjB,KAAK,SAA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