@jsii/kernel 1.68.0 → 1.69.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/lib/kernel.js CHANGED
@@ -4,14 +4,12 @@ exports.Kernel = exports.RuntimeError = exports.JsiiFault = void 0;
4
4
  const spec = require("@jsii/spec");
5
5
  const spec_1 = require("@jsii/spec");
6
6
  const cp = require("child_process");
7
- const fs_1 = require("fs");
8
7
  const fs = require("fs-extra");
9
8
  const module_1 = require("module");
10
9
  const os = require("os");
11
10
  const path = require("path");
12
11
  const api = require("./api");
13
12
  const api_1 = require("./api");
14
- const link_1 = require("./link");
15
13
  const objects_1 = require("./objects");
16
14
  const onExit = require("./on-exit");
17
15
  const wire = require("./serialization");
@@ -88,21 +86,13 @@ class Kernel {
88
86
  const originalUmask = process.umask(0o022);
89
87
  try {
90
88
  // untar the archive to its final location
91
- const { path: extractedTo, cache } = this._debugTime(() => tar.extract(req.tarball, {
89
+ const { cache } = this._debugTime(() => tar.extract(req.tarball, packageDir, {
92
90
  strict: true,
93
91
  strip: 1,
94
92
  unlink: true,
95
93
  }, req.name, req.version), `tar.extract(${req.tarball}) => ${packageDir}`);
96
- // Create the install directory (there may be several path components for @scoped/packages)
97
- fs.mkdirSync(path.dirname(packageDir), { recursive: true });
98
94
  if (cache != null) {
99
95
  this._debug(`Package cache enabled, extraction resulted in a cache ${cache}`);
100
- // Link the package into place.
101
- this._debugTime(() => (0, link_1.link)(extractedTo, packageDir), `link(${extractedTo}, ${packageDir})`);
102
- }
103
- else {
104
- // This is not from cache, so we move it around instead of copying.
105
- (0, fs_1.renameSync)(extractedTo, packageDir);
106
96
  }
107
97
  }
108
98
  finally {
@@ -1,10 +1,6 @@
1
1
  import * as tar from 'tar';
2
2
  export declare type ExtractOptions = Omit<tar.ExtractOptions & tar.FileOptions, 'file' | 'cwd'>;
3
3
  export interface ExtractResult {
4
- /**
5
- * The path in which the extracted files are located
6
- */
7
- readonly path: string;
8
4
  /**
9
5
  * When `'hit'`, the data was already present in cache and was returned from
10
6
  * cache.
@@ -25,7 +21,7 @@ export interface ExtractResult {
25
21
  *
26
22
  * @returns the result of the extraction.
27
23
  */
28
- export declare function extract(file: string, options: ExtractOptions, ...comments: readonly string[]): ExtractResult;
24
+ export declare function extract(file: string, outDir: string, options: ExtractOptions, ...comments: readonly string[]): ExtractResult;
29
25
  /** @internal */
30
26
  export declare function getPackageCacheEnabled(): boolean;
31
27
  /** @internal */
@@ -3,10 +3,9 @@ var _a;
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.setPackageCacheEnabled = exports.getPackageCacheEnabled = exports.extract = void 0;
5
5
  const fs_1 = require("fs");
6
- const os_1 = require("os");
7
- const path_1 = require("path");
8
6
  const tar = require("tar");
9
7
  const disk_cache_1 = require("../disk-cache");
8
+ const link_1 = require("../link");
10
9
  const default_cache_root_1 = require("./default-cache-root");
11
10
  let packageCacheEnabled = ((_a = process.env.JSII_RUNTIME_PACKAGE_CACHE) === null || _a === void 0 ? void 0 : _a.toLocaleUpperCase()) === 'enabled';
12
11
  /**
@@ -18,27 +17,36 @@ let packageCacheEnabled = ((_a = process.env.JSII_RUNTIME_PACKAGE_CACHE) === nul
18
17
  *
19
18
  * @returns the result of the extraction.
20
19
  */
21
- function extract(file, options, ...comments) {
22
- return (packageCacheEnabled ? extractToCache : extractToTemporary)(file, options, ...comments);
20
+ function extract(file, outDir, options, ...comments) {
21
+ (0, fs_1.mkdirSync)(outDir, { recursive: true });
22
+ try {
23
+ return (packageCacheEnabled ? extractViaCache : extractToOutDir)(file, outDir, options, ...comments);
24
+ }
25
+ catch (err) {
26
+ (0, fs_1.rmSync)(outDir, { force: true, recursive: true });
27
+ throw err;
28
+ }
23
29
  }
24
30
  exports.extract = extract;
25
- function extractToCache(file, options = {}, ...comments) {
31
+ function extractViaCache(file, outDir, options = {}, ...comments) {
26
32
  var _a;
27
33
  const cacheRoot = (_a = process.env.JSII_RUNTIME_PACKAGE_CACHE_ROOT) !== null && _a !== void 0 ? _a : (0, default_cache_root_1.defaultCacheRoot)();
28
- const cache = disk_cache_1.DiskCache.inDirectory(cacheRoot);
29
- const entry = cache.entryFor(file, ...comments);
30
- return entry.lock((lock) => {
34
+ const dirCache = disk_cache_1.DiskCache.inDirectory(cacheRoot);
35
+ const entry = dirCache.entryFor(file, ...comments);
36
+ const { path, cache } = entry.lock((lock) => {
31
37
  let cache = 'hit';
32
38
  if (!entry.pathExists) {
33
- const tmpPath = `${entry.path}.tmp`;
34
- (0, fs_1.mkdirSync)(tmpPath, { recursive: true });
39
+ // !!!IMPORTANT!!!
40
+ // Extract directly into the final target directory, as certain antivirus
41
+ // software configurations on Windows will make a `renameSync` operation
42
+ // fail with EPERM until the files have been fully analyzed.
43
+ (0, fs_1.mkdirSync)(entry.path, { recursive: true });
35
44
  try {
36
45
  untarInto({
37
46
  ...options,
38
- cwd: tmpPath,
47
+ cwd: entry.path,
39
48
  file,
40
49
  });
41
- (0, fs_1.renameSync)(tmpPath, entry.path);
42
50
  }
43
51
  catch (error) {
44
52
  (0, fs_1.rmSync)(entry.path, { force: true, recursive: true });
@@ -49,11 +57,16 @@ function extractToCache(file, options = {}, ...comments) {
49
57
  lock.touch();
50
58
  return { path: entry.path, cache };
51
59
  });
60
+ (0, link_1.link)(path, outDir);
61
+ return { cache };
52
62
  }
53
- function extractToTemporary(file, options = {}) {
54
- const path = (0, fs_1.mkdtempSync)((0, path_1.join)((0, os_1.tmpdir)(), 'jsii-runtime-untar-'));
55
- untarInto({ ...options, cwd: path, file });
56
- return { path };
63
+ function extractToOutDir(file, cwd, options = {}) {
64
+ // !!!IMPORTANT!!!
65
+ // Extract directly into the final target directory, as certain antivirus
66
+ // software configurations on Windows will make a `renameSync` operation
67
+ // fail with EPERM until the files have been fully analyzed.
68
+ untarInto({ ...options, cwd, file });
69
+ return {};
57
70
  }
58
71
  function untarInto(options) {
59
72
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jsii/kernel",
3
- "version": "1.68.0",
3
+ "version": "1.69.0",
4
4
  "description": "kernel for jsii execution environment",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -31,19 +31,19 @@
31
31
  "package": "package-js"
32
32
  },
33
33
  "dependencies": {
34
- "@jsii/spec": "^1.68.0",
34
+ "@jsii/spec": "^1.69.0",
35
35
  "fs-extra": "^10.1.0",
36
36
  "lockfile": "^1.0.4",
37
37
  "tar": "^6.1.11"
38
38
  },
39
39
  "devDependencies": {
40
- "@scope/jsii-calc-base": "^1.68.0",
41
- "@scope/jsii-calc-lib": "^1.68.0",
40
+ "@scope/jsii-calc-base": "^1.69.0",
41
+ "@scope/jsii-calc-lib": "^1.69.0",
42
42
  "@types/fs-extra": "^9.0.13",
43
43
  "@types/lockfile": "^1.0.2",
44
44
  "@types/tar": "^6.1.2",
45
45
  "jest-expect-message": "^1.1.2",
46
- "jsii-build-tools": "^1.68.0",
46
+ "jsii-build-tools": "^1.69.0",
47
47
  "jsii-calc": "^3.20.120"
48
48
  }
49
49
  }