@atlaspack/build-cache 2.13.4-unified-f165f7d09.0 → 2.13.5-dev-inline-requires-reuse-bdc9ca9c3.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/CHANGELOG.md +6 -0
- package/lib/serializer.js +4 -0
- package/lib/types/buildCache.d.ts +2 -0
- package/{src/index.js → lib/types/index.d.ts} +0 -2
- package/lib/types/serializer.d.ts +11 -0
- package/lib/types/serializerCore.d.ts +2 -0
- package/package.json +9 -4
- package/src/{buildCache.js → buildCache.ts} +0 -2
- package/src/index.ts +3 -0
- package/src/{serializer.js → serializer.ts} +10 -7
- package/src/serializerCore.ts +4 -0
- package/test/{serializer.test.js → serializer.test.ts} +6 -8
- package/tsconfig.json +4 -0
- package/src/serializerCore.js +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaspack/build-cache
|
|
2
2
|
|
|
3
|
+
## 2.13.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#720](https://github.com/atlassian-labs/atlaspack/pull/720) [`d2fd849`](https://github.com/atlassian-labs/atlaspack/commit/d2fd849770fe6305e9c694bd97b1bd905abd9d94) Thanks [@alshdavid](https://github.com/alshdavid)! - Migrate to TypeScript
|
|
8
|
+
|
|
3
9
|
## 2.13.3
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/lib/serializer.js
CHANGED
|
@@ -26,6 +26,10 @@ Object.defineProperty(exports, "serializeRaw", {
|
|
|
26
26
|
exports.unregisterSerializableClass = unregisterSerializableClass;
|
|
27
27
|
var _buildCache = require("./buildCache");
|
|
28
28
|
var _serializerCore = require("./serializerCore");
|
|
29
|
+
// flow-to-ts helpers
|
|
30
|
+
|
|
31
|
+
// /flow-to-ts helpers
|
|
32
|
+
|
|
29
33
|
const nameToCtor = new Map();
|
|
30
34
|
const ctorToName = new Map();
|
|
31
35
|
function registerSerializableClass(name, ctor) {
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { serializeRaw, deserializeRaw } from './serializerCore';
|
|
2
|
+
export type Class<T> = new (...args: any[]) => T;
|
|
3
|
+
export declare function registerSerializableClass(name: string, ctor: Class<any>): void;
|
|
4
|
+
export declare function unregisterSerializableClass(name: string, ctor: Class<any>): void;
|
|
5
|
+
export declare function prepareForSerialization(object: any): any;
|
|
6
|
+
export declare function restoreDeserializedObject(object: any): any;
|
|
7
|
+
export declare function serialize(object: any): Buffer;
|
|
8
|
+
export declare function deserialize(buffer: Buffer): any;
|
|
9
|
+
export declare function cacheSerializedObject(object: any, buffer?: Buffer): void;
|
|
10
|
+
export declare function deserializeToCache(buffer: Buffer): any;
|
|
11
|
+
export declare function removeSerializedObjectFromCache(object: any): void;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaspack/build-cache",
|
|
3
3
|
"description": "Serialize and deserialize data structures to a build cache",
|
|
4
|
-
"version": "2.13.
|
|
4
|
+
"version": "2.13.5-dev-inline-requires-reuse-bdc9ca9c3.0",
|
|
5
5
|
"license": "(MIT OR Apache-2.0)",
|
|
6
6
|
"type": "commonjs",
|
|
7
7
|
"publishConfig": {
|
|
@@ -11,10 +11,15 @@
|
|
|
11
11
|
"type": "git",
|
|
12
12
|
"url": "https://github.com/atlassian-labs/atlaspack.git"
|
|
13
13
|
},
|
|
14
|
-
"main": "lib/index.js",
|
|
15
|
-
"source": "src/index.
|
|
14
|
+
"main": "./lib/index.js",
|
|
15
|
+
"source": "./src/index.ts",
|
|
16
|
+
"types": "./lib/types/index.d.ts",
|
|
16
17
|
"engines": {
|
|
17
18
|
"node": ">= 16.0.0"
|
|
18
19
|
},
|
|
19
|
-
"
|
|
20
|
+
"scripts": {
|
|
21
|
+
"check-ts": "tsc --emitDeclarationOnly --rootDir src",
|
|
22
|
+
"build:lib": "gulp build --gulpfile ../../../gulpfile.js --cwd ."
|
|
23
|
+
},
|
|
24
|
+
"gitHead": "bdc9ca9c38f45155a6d6f280e343a29e3f030a83"
|
|
20
25
|
}
|
package/src/index.ts
ADDED
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
// @flow
|
|
2
1
|
import {createBuildCache} from './buildCache';
|
|
3
2
|
import {serializeRaw, deserializeRaw} from './serializerCore';
|
|
4
3
|
|
|
5
4
|
export {serializeRaw, deserializeRaw} from './serializerCore';
|
|
6
5
|
|
|
6
|
+
// flow-to-ts helpers
|
|
7
|
+
export type Class<T> = new (...args: any[]) => T;
|
|
8
|
+
// /flow-to-ts helpers
|
|
9
|
+
|
|
7
10
|
const nameToCtor: Map<string, Class<any>> = new Map();
|
|
8
11
|
const ctorToName: Map<Class<any>, string> = new Map();
|
|
9
12
|
|
|
@@ -49,7 +52,7 @@ function shallowCopy(object: any) {
|
|
|
49
52
|
return object;
|
|
50
53
|
}
|
|
51
54
|
|
|
52
|
-
function isBuffer(object) {
|
|
55
|
+
function isBuffer(object: any) {
|
|
53
56
|
return (
|
|
54
57
|
object.buffer instanceof ArrayBuffer ||
|
|
55
58
|
(typeof SharedArrayBuffer !== 'undefined' &&
|
|
@@ -57,11 +60,11 @@ function isBuffer(object) {
|
|
|
57
60
|
);
|
|
58
61
|
}
|
|
59
62
|
|
|
60
|
-
function shouldContinueMapping(value) {
|
|
63
|
+
function shouldContinueMapping(value: any) {
|
|
61
64
|
return value && typeof value === 'object' && value.$$raw !== true;
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
function mapObject(object: any, fn: (val
|
|
67
|
+
function mapObject(object: any, fn: (val?: any) => any, preOrder = false): any {
|
|
65
68
|
let cache = new Map();
|
|
66
69
|
let memo = new Map();
|
|
67
70
|
|
|
@@ -211,8 +214,8 @@ export function restoreDeserializedObject(object: any): any {
|
|
|
211
214
|
);
|
|
212
215
|
}
|
|
213
216
|
|
|
214
|
-
if (typeof ctor.deserialize === 'function') {
|
|
215
|
-
return ctor.deserialize(value.value);
|
|
217
|
+
if (typeof (ctor as any).deserialize === 'function') {
|
|
218
|
+
return (ctor as any).deserialize(value.value);
|
|
216
219
|
}
|
|
217
220
|
|
|
218
221
|
value = value.value;
|
|
@@ -223,7 +226,7 @@ export function restoreDeserializedObject(object: any): any {
|
|
|
223
226
|
});
|
|
224
227
|
}
|
|
225
228
|
|
|
226
|
-
const serializeCache = createBuildCache();
|
|
229
|
+
const serializeCache = createBuildCache<any, Buffer>();
|
|
227
230
|
|
|
228
231
|
export function serialize(object: any): Buffer {
|
|
229
232
|
let cached = serializeCache.get(object);
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
|
|
3
1
|
import assert from 'assert';
|
|
4
2
|
import sinon from 'sinon';
|
|
5
3
|
|
|
@@ -151,8 +149,8 @@ describe('serializer', () => {
|
|
|
151
149
|
|
|
152
150
|
it('should serialize a cyclic class', () => {
|
|
153
151
|
class Foo {
|
|
154
|
-
x:
|
|
155
|
-
constructor(x
|
|
152
|
+
x: Foo | null | undefined;
|
|
153
|
+
constructor(x?: Foo | null) {
|
|
156
154
|
this.x = x;
|
|
157
155
|
}
|
|
158
156
|
}
|
|
@@ -193,8 +191,8 @@ describe('serializer', () => {
|
|
|
193
191
|
|
|
194
192
|
it('should serialize a cyclic class and copy on write', () => {
|
|
195
193
|
class Foo {
|
|
196
|
-
x:
|
|
197
|
-
constructor(x
|
|
194
|
+
x: Foo | null | undefined;
|
|
195
|
+
constructor(x?: Foo | null) {
|
|
198
196
|
this.x = x;
|
|
199
197
|
}
|
|
200
198
|
}
|
|
@@ -257,7 +255,7 @@ describe('serializer', () => {
|
|
|
257
255
|
class Outer {
|
|
258
256
|
inner: Inner;
|
|
259
257
|
|
|
260
|
-
constructor(inner) {
|
|
258
|
+
constructor(inner: any) {
|
|
261
259
|
this.inner = inner;
|
|
262
260
|
}
|
|
263
261
|
|
|
@@ -272,7 +270,7 @@ describe('serializer', () => {
|
|
|
272
270
|
class Inner {
|
|
273
271
|
x: number;
|
|
274
272
|
|
|
275
|
-
constructor(x) {
|
|
273
|
+
constructor(x: any) {
|
|
276
274
|
this.x = x;
|
|
277
275
|
}
|
|
278
276
|
|
package/tsconfig.json
ADDED