tar-utils 2.1.3 → 3.0.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,28 @@
1
+ name: Flowzone
2
+
3
+ on:
4
+ pull_request:
5
+ types: [opened, synchronize, closed]
6
+ branches:
7
+ - "main"
8
+ - "master"
9
+ pull_request_target:
10
+ types: [opened, synchronize, closed]
11
+ branches:
12
+ - "main"
13
+ - "master"
14
+
15
+ jobs:
16
+ flowzone:
17
+ name: Flowzone
18
+ uses: product-os/flowzone/.github/workflows/flowzone.yml@master
19
+ # prevent duplicate workflow executions for pull_request and pull_request_target
20
+ if: |
21
+ (
22
+ github.event.pull_request.head.repo.full_name == github.repository &&
23
+ github.event_name == 'pull_request'
24
+ ) || (
25
+ github.event.pull_request.head.repo.full_name != github.repository &&
26
+ github.event_name == 'pull_request_target'
27
+ )
28
+ secrets: inherit
@@ -1,61 +1,86 @@
1
+ - commits:
2
+ - subject: Update tar-stream to 3.x
3
+ hash: f4e87ea24df2acb73d1227049835b992d03e0778
4
+ body: ""
5
+ footer:
6
+ Change-type: major
7
+ change-type: major
8
+ author: Pagan Gazzard
9
+ - subject: Switch from bluebird to native promises
10
+ hash: 2a5f004a5319550c5070453207f00ea20f3fc4c3
11
+ body: ""
12
+ footer:
13
+ Change-type: major
14
+ change-type: major
15
+ author: Pagan Gazzard
16
+ - subject: Update minimum nodejs version to 16.13.0
17
+ hash: 6c589624a856cd99bd3d8c2c6c81803f9592a948
18
+ body: ""
19
+ footer:
20
+ Change-type: major
21
+ change-type: major
22
+ author: Pagan Gazzard
23
+ version: 3.0.0
24
+ title: ""
25
+ date: 2023-07-05T13:07:23.972Z
1
26
  - commits:
2
27
  - subject: Add .version/CHANGELOG.yml for nested changelogs
3
28
  hash: ad1f96a9114c7135870939710f100fd2ef6ba154
4
- body: ''
29
+ body: ""
5
30
  footer:
6
31
  Change-type: patch
7
32
  change-type: patch
8
33
  author: Pagan Gazzard
9
34
  version: 2.1.3
10
- date: 2020-08-20T18:05:29.515Z
35
+ date: 2020-08-20T18:01:29.420Z
11
36
  - commits:
12
37
  - author: Pagan Gazzard
13
- body: ''
38
+ body: ""
14
39
  footers:
15
40
  change-type: patch
16
41
  hash: 7f66c68e735a9779aadb9b04891d3022ce4e6dc7
17
42
  subject: Explicitly disable backpressure in `cloneTarStream` to buffer in memory
18
43
  - author: Pagan Gazzard
19
- body: ''
44
+ body: ""
20
45
  footers:
21
46
  change-type: patch
22
47
  hash: 3c49d50c543300733fb5e2e2324251f855e87b19
23
48
  subject: Remove lodash dependency
24
49
  - author: Pagan Gazzard
25
- body: ''
50
+ body: ""
26
51
  hash: 7c840b80fce0bbd1f7dfdd415bf7b1acf1ab312a
27
52
  subject: Switch to @balena/lint
28
- date: '2020-08-14T11:31:15Z'
53
+ date: 2020-08-14T11:31:15Z
29
54
  version: 2.1.2
30
55
  - commits:
31
56
  - author: Paulo Castro
32
- body: ''
57
+ body: ""
33
58
  footers:
34
59
  change-type: patch
35
60
  hash: 46e9b0a6714e3017b1b14fd2fdfccb38eee9e551
36
61
  subject: Fix documentation for normalizeTarEntry
37
62
  - author: Paulo Castro
38
- body: ''
63
+ body: ""
39
64
  footers:
40
65
  change-type: patch
41
66
  hash: 74c7d9e9231aa41c160355528856a8dd7106723f
42
- subject: 'Update gulp for Node v12, and update gulpfile for gulp v4'
67
+ subject: Update gulp for Node v12, and update gulpfile for gulp v4
43
68
  - author: Paulo Castro
44
- body: ''
69
+ body: ""
45
70
  footers:
46
71
  change-type: patch
47
72
  hash: 31ff953aadf3a8d5f51922d93c7c416cf39d403c
48
73
  subject: Pin tar-stream to v2.1.1 to avoid a sudden silent process crash
49
- date: '2020-08-13T21:59:34Z'
74
+ date: 2020-08-13T21:59:34Z
50
75
  version: 2.1.1
51
76
  - commits:
52
77
  - author: Pagan Gazzard
53
- body: ''
78
+ body: ""
54
79
  footers:
55
80
  change-type: minor
56
81
  hash: 05d16cba3ac6cc603c33b9ce67dde95a4d5291c0
57
82
  subject: Update dependencies and use declaration files for types
58
- date: '2020-03-04T12:16:22Z'
83
+ date: 2020-03-04T12:16:22Z
59
84
  version: 2.1.0
60
85
  - commits:
61
86
  - author: Paulo Castro
@@ -64,71 +89,70 @@
64
89
  the change-type is major.
65
90
  footers:
66
91
  change-type: major
67
- connects-to: 'https://github.com/balena-io/balena-cli/issues/1133'
92
+ connects-to: https://github.com/balena-io/balena-cli/issues/1133
68
93
  signed-off-by: Paulo Castro <paulo@balena.io>
69
94
  hash: 7aaa90613a6a457d57a7edd64ff5101f39a2c73f
70
95
  subject: Fix path separator used by normalizeTarEntry() under Windows.
71
- date: '2019-04-16T12:31:27Z'
96
+ date: 2019-04-16T12:31:27Z
72
97
  version: 2.0.0
73
98
  - commits:
74
99
  - author: Paulo Castro
75
- body: ''
100
+ body: ""
76
101
  footers:
77
102
  change-type: minor
78
103
  signed-off-by: Paulo Castro <paulo@balena.io>
79
104
  hash: 01835dda5bc3ea7388f64d2a739b704624c2f6a5
80
- subject: 'Added pipePromise, cloneTarStream and multicastStream functions'
81
- date: '2019-02-18T16:15:09Z'
105
+ subject: Added pipePromise, cloneTarStream and multicastStream functions
106
+ date: 2019-02-18T16:15:09Z
82
107
  version: 1.1.0
83
108
  - commits:
84
109
  - author: Pagan Gazzard
85
- body: ''
110
+ body: ""
86
111
  footers:
87
112
  change-type: patch
88
113
  hash: 3783e6c9ce63225a4ca4c9a8c1b9693d72f0ed76
89
- subject: >-
90
- Only concat buffers once at the end, reducing the amount of copying and
114
+ subject: Only concat buffers once at the end, reducing the amount of copying and
91
115
  garbage collection massively.
92
- date: '2018-07-17T18:18:19Z'
116
+ date: 2018-07-17T18:18:19Z
93
117
  version: 1.0.6
94
118
  - commits:
95
119
  - author: Pagan Gazzard
96
- body: ''
120
+ body: ""
97
121
  footers:
98
122
  change-type: patch
99
123
  hash: e88cf7626cc59b50b585e96f33575d7f5d0e4296
100
124
  subject: Fixes for use on windows
101
- date: '2018-07-17T18:05:14Z'
125
+ date: 2018-07-17T18:05:14Z
102
126
  version: 1.0.5
103
127
  - commits:
104
128
  - author: Pagan Gazzard
105
- body: ''
129
+ body: ""
106
130
  footers:
107
131
  change-type: patch
108
132
  hash: a8f8a9d004874dd30731e4cd7a2545d68ed10e7f
109
133
  subject: Ignore node_modules
110
- date: '2018-07-17T17:50:09Z'
134
+ date: 2018-07-17T17:50:09Z
111
135
  version: 1.0.4
112
136
  - commits:
113
137
  - author: Pagan Gazzard
114
- body: ''
138
+ body: ""
115
139
  hash: 7ea0c561b3917db05a60329910c681730c723f69
116
140
  subject: Add versionist
117
141
  - author: Pagan Gazzard
118
- body: ''
142
+ body: ""
119
143
  footers:
120
144
  change-type: patch
121
145
  hash: 54c75df4473384fae89ba0a6cd42fcf820470436
122
146
  subject: Enable circleci testing and auto-publishing.
123
- date: '2018-07-17T17:39:15Z'
147
+ date: 2018-07-17T17:39:15Z
124
148
  version: 1.0.3
125
149
  - commits:
126
150
  - author: Cameron Diver
127
- body: ''
151
+ body: ""
128
152
  footers:
129
153
  change-type: patch
130
154
  signed-off-by: Cameron Diver <cameron@resin.io>
131
155
  hash: 9d0c4d93d76a9458af4c479d7455c5f287699cdb
132
156
  subject: Update dependencies and clean up project
133
- date: '2017-12-04T12:10:16Z'
157
+ date: 2017-12-04T12:10:16Z
134
158
  version: 1.0.2
package/CHANGELOG.md CHANGED
@@ -4,6 +4,13 @@ All notable changes to this project will be documented in this file
4
4
  automatically by Versionist. DO NOT EDIT THIS FILE MANUALLY!
5
5
  This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ # v3.0.0
8
+ ## (2023-07-05)
9
+
10
+ * Update tar-stream to 3.x [Pagan Gazzard]
11
+ * Switch from bluebird to native promises [Pagan Gazzard]
12
+ * Update minimum nodejs version to 16.13.0 [Pagan Gazzard]
13
+
7
14
  # v2.1.3
8
15
  ## (2020-08-20)
9
16
 
package/build/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
1
  /// <reference types="node" />
2
- import * as Bluebird from 'bluebird';
2
+ /// <reference types="node" />
3
3
  import { Readable, Writable } from 'stream';
4
4
  import * as tar from 'tar-stream';
5
5
  export declare function normalizeTarEntry(name: string): string;
6
- export declare function streamToBuffer(stream: Readable): Bluebird<Buffer>;
7
- export declare function drainStream(stream: Readable): Bluebird<void>;
8
- export declare function pipePromise<WritableSub extends Writable>(pipeFrom: Readable, pipeTo: WritableSub): Bluebird<WritableSub>;
6
+ export declare function streamToBuffer(stream: Readable): Promise<Buffer>;
7
+ export declare function drainStream(stream: Readable): Promise<void>;
8
+ export declare function pipePromise<WritableSub extends Writable>(pipeFrom: Readable, pipeTo: WritableSub): Promise<WritableSub>;
9
9
  export declare function cloneTarStream(sourceTarStream: Readable, opts?: {
10
10
  onEntry?: (pack: tar.Pack, header: tar.Headers, stream: Readable) => void;
11
11
  onFinish?: (pack: tar.Pack) => void;
12
- }): Bluebird<tar.Pack>;
13
- export declare function multicastStream(fromStream: Readable, toStreams: Writable[]): Bluebird<void>;
12
+ }): Promise<tar.Pack>;
13
+ export declare function multicastStream(fromStream: Readable, toStreams: Writable[]): Promise<void>;
package/build/index.js CHANGED
@@ -1,7 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.multicastStream = exports.cloneTarStream = exports.pipePromise = exports.drainStream = exports.streamToBuffer = exports.normalizeTarEntry = void 0;
4
- const Bluebird = require("bluebird");
5
4
  const path = require("path");
6
5
  const tar = require("tar-stream");
7
6
  function noop() {
@@ -13,53 +12,61 @@ function normalizeTarEntry(name) {
13
12
  return path.posix.normalize(name).replace(/^\/+|\/+$/g, '') || '.';
14
13
  }
15
14
  exports.normalizeTarEntry = normalizeTarEntry;
16
- function streamToBuffer(stream) {
15
+ async function streamToBuffer(stream) {
17
16
  let onData;
18
17
  let onError;
19
18
  let onEnd;
20
- return new Bluebird((resolve, reject) => {
21
- const chunks = [];
22
- stream.on('end', (onEnd = () => resolve(chunks)));
23
- stream.on('error', (onError = reject));
24
- stream.on('data', (onData = (data) => chunks.push(data)));
25
- })
26
- .then(Buffer.concat)
27
- .finally(() => {
28
- stream.removeListener('data', onData || noop);
29
- stream.removeListener('error', onError || noop);
30
- stream.removeListener('end', onEnd || noop);
31
- });
19
+ try {
20
+ const buffers = await new Promise((resolve, reject) => {
21
+ const chunks = [];
22
+ stream.on('end', (onEnd = () => resolve(chunks)));
23
+ stream.on('error', (onError = reject));
24
+ stream.on('data', (onData = (data) => chunks.push(data)));
25
+ });
26
+ return Buffer.concat(buffers);
27
+ }
28
+ finally {
29
+ stream.removeListener('data', onData ?? noop);
30
+ stream.removeListener('error', onError ?? noop);
31
+ stream.removeListener('end', onEnd ?? noop);
32
+ }
32
33
  }
33
34
  exports.streamToBuffer = streamToBuffer;
34
- function drainStream(stream) {
35
+ async function drainStream(stream) {
35
36
  let onError;
36
37
  let onEnd;
37
- return new Bluebird((resolve, reject) => {
38
- stream.on('error', (onError = reject));
39
- stream.on('end', (onEnd = resolve));
40
- stream.resume();
41
- }).finally(() => {
42
- stream.removeListener('error', onError || noop);
43
- stream.removeListener('end', onEnd || noop);
44
- });
38
+ try {
39
+ return await new Promise((resolve, reject) => {
40
+ stream.on('error', (onError = reject));
41
+ stream.on('end', (onEnd = resolve));
42
+ stream.resume();
43
+ });
44
+ }
45
+ finally {
46
+ stream.removeListener('error', onError ?? noop);
47
+ stream.removeListener('end', onEnd ?? noop);
48
+ }
45
49
  }
46
50
  exports.drainStream = drainStream;
47
- function pipePromise(pipeFrom, pipeTo) {
51
+ async function pipePromise(pipeFrom, pipeTo) {
48
52
  let onError;
49
53
  let onFinish;
50
- return new Bluebird((resolve, reject) => {
51
- pipeFrom.on('error', (onError = reject));
52
- pipeTo.on('error', onError);
53
- pipeTo.on('finish', (onFinish = () => resolve(pipeTo)));
54
- pipeFrom.pipe(pipeTo);
55
- }).finally(() => {
56
- pipeFrom.removeListener('error', onError || noop);
57
- pipeTo.removeListener('error', onError || noop);
58
- pipeTo.removeListener('finish', onFinish || noop);
59
- });
54
+ try {
55
+ return await new Promise((resolve, reject) => {
56
+ pipeFrom.on('error', (onError = reject));
57
+ pipeTo.on('error', onError);
58
+ pipeTo.on('finish', (onFinish = () => resolve(pipeTo)));
59
+ pipeFrom.pipe(pipeTo);
60
+ });
61
+ }
62
+ finally {
63
+ pipeFrom.removeListener('error', onError ?? noop);
64
+ pipeTo.removeListener('error', onError ?? noop);
65
+ pipeTo.removeListener('finish', onFinish ?? noop);
66
+ }
60
67
  }
61
68
  exports.pipePromise = pipePromise;
62
- function cloneTarStream(sourceTarStream, opts) {
69
+ async function cloneTarStream(sourceTarStream, opts) {
63
70
  const extract = tar.extract();
64
71
  const pack = tar.pack();
65
72
  const origPush = pack.push;
@@ -69,62 +76,82 @@ function cloneTarStream(sourceTarStream, opts) {
69
76
  };
70
77
  let packOnError;
71
78
  let sourceTarStreamOnError;
72
- return new Bluebird((resolve, reject) => {
73
- packOnError = reject;
74
- sourceTarStreamOnError = reject;
75
- sourceTarStream.on('error', sourceTarStreamOnError);
76
- pack.on('error', packOnError);
77
- extract.on('error', reject);
78
- extract.on('entry', (header, stream, callback) => {
79
- if (opts && opts.onEntry) {
80
- Bluebird.try(() => opts.onEntry(pack, header, stream)).then(callback, callback);
81
- }
82
- else {
83
- streamToBuffer(stream).then(buf => {
84
- pack.entry(header, buf, callback);
85
- });
86
- }
87
- });
88
- extract.once('finish', () => {
89
- Bluebird.try(() => {
90
- if (opts && opts.onFinish) {
91
- return opts.onFinish(pack);
79
+ try {
80
+ return await new Promise((resolve, reject) => {
81
+ packOnError = reject;
82
+ sourceTarStreamOnError = reject;
83
+ sourceTarStream.on('error', sourceTarStreamOnError);
84
+ pack.on('error', packOnError);
85
+ extract.on('error', reject);
86
+ extract.on('entry', async (header, stream, callback) => {
87
+ if (opts?.onEntry) {
88
+ try {
89
+ await opts.onEntry(pack, header, stream);
90
+ }
91
+ catch (err) {
92
+ callback(err);
93
+ }
92
94
  }
93
- })
94
- .then(() => {
95
- pack.finalize();
96
- resolve(pack);
97
- })
98
- .catch(reject);
95
+ else {
96
+ const buf = await streamToBuffer(stream);
97
+ if (header.type !== 'file' && header.type !== 'contiguous-file') {
98
+ pack.entry(header, callback);
99
+ }
100
+ else {
101
+ pack.entry(header, buf, callback);
102
+ }
103
+ }
104
+ });
105
+ extract.once('finish', async () => {
106
+ try {
107
+ if (opts?.onFinish) {
108
+ await opts.onFinish(pack);
109
+ }
110
+ pack.finalize();
111
+ resolve(pack);
112
+ }
113
+ catch (err) {
114
+ reject(err);
115
+ }
116
+ });
117
+ sourceTarStream.pipe(extract);
99
118
  });
100
- sourceTarStream.pipe(extract);
101
- }).finally(() => {
102
- sourceTarStream.removeListener('error', sourceTarStreamOnError || noop);
103
- pack.removeListener('error', packOnError || noop);
104
- });
119
+ }
120
+ finally {
121
+ sourceTarStream.removeListener('error', sourceTarStreamOnError ?? noop);
122
+ pack.removeListener('error', packOnError ?? noop);
123
+ }
105
124
  }
106
125
  exports.cloneTarStream = cloneTarStream;
107
- function multicastStream(fromStream, toStreams) {
126
+ async function multicastStream(fromStream, toStreams) {
108
127
  if (toStreams.length === 0) {
109
- return Bluebird.resolve();
128
+ return;
110
129
  }
111
130
  let onError;
112
- return new Bluebird((resolve, reject) => {
113
- Bluebird.all(toStreams.map((toStream) => {
114
- let onFinish;
115
- return new Bluebird(toStreamResolve => toStream.on('finish', (onFinish = toStreamResolve))).finally(() => toStream.removeListener('finish', onFinish || noop));
116
- }))
117
- .then(() => resolve())
118
- .catch(reject);
119
- fromStream.on('error', (onError = reject));
120
- for (const toStream of toStreams) {
121
- toStream.on('error', onError);
122
- fromStream.pipe(toStream);
123
- }
124
- }).finally(() => {
125
- fromStream.removeListener('error', onError || noop);
126
- toStreams.forEach(toStream => toStream.removeListener('error', onError || noop));
127
- });
131
+ try {
132
+ return await new Promise((resolve, reject) => {
133
+ Promise.all(toStreams.map(async (toStream) => {
134
+ let onFinish;
135
+ try {
136
+ return await new Promise((toStreamResolve) => toStream.on('finish', (onFinish = toStreamResolve)));
137
+ }
138
+ finally {
139
+ toStream.removeListener('finish', onFinish ?? noop);
140
+ }
141
+ }))
142
+ .then(() => resolve())
143
+ .catch(reject);
144
+ fromStream.on('error', (onError = reject));
145
+ for (const toStream of toStreams) {
146
+ toStream.on('error', onError);
147
+ fromStream.pipe(toStream);
148
+ }
149
+ });
150
+ }
151
+ finally {
152
+ fromStream.removeListener('error', onError ?? noop);
153
+ toStreams.forEach((toStream) => toStream.removeListener('error', onError ?? noop));
154
+ }
128
155
  }
129
156
  exports.multicastStream = multicastStream;
130
157
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":";;;AAgBA,qCAAqC;AACrC,6BAA6B;AAE7B,kCAAkC;AAElC,SAAS,IAAI;AAEb,CAAC;AAeD,SAAgB,iBAAiB,CAAC,IAAY;IAC7C,IAAI,CAAC,IAAI,EAAE;QACV,OAAO,EAAE,CAAC;KACV;IAOD,OAAO,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,EAAE,CAAC,IAAI,GAAG,CAAC;AACpE,CAAC;AAXD,8CAWC;AAMD,SAAgB,cAAc,CAAC,MAAgB;IAC9C,IAAI,MAA8B,CAAC;IACnC,IAAI,OAA+B,CAAC;IACpC,IAAI,KAAiB,CAAC;IACtB,OAAO,IAAI,QAAQ,CAAW,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;QACjD,MAAM,MAAM,GAAa,EAAE,CAAC;QAC5B,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAClD,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;QAEvC,MAAM,CAAC,EAAE,CAAC,M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AAI;QACH,OAAO,MAAM,IAAI,OAAO,CAAO,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YAGlD,OAAO,CAAC,GAAG,CACV,SAAS,CAAC,GAAG,CAAC,KAAK,EAAE,QAAkB,EAAE,EAAE;gBAC1C,IAAI,QAAkC,CAAC;gBACvC,IAAI;oBACH,OAAO,MAAM,IAAI,OAAO,CAAO,CAAC,eAAe,EAAE,EAAE,CAClD,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,QAAQ,GAAG,eAAe,CAAC,CAAC,CACnD,CAAC;iBACF;wBAAS;oBACT,QAAQ,CAAC,cAAc,CAAC,QAAQ,EAAE,QAAQ,IAAI,IAAI,CAAC,CAAC;iBACpD;YACF,CAAC,CAAC,CACF;iBACC,IAAI,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,CAAC;iBACrB,KAAK,CAAC,MAAM,CAAC,CAAC;YAEhB,UAAU,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,OAAO,GAAG,MAAM,CAAC,CAAC,CAAC;YAC3C,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE;gBACjC,QAAQ,CAAC,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;gBAC9B,UAAU,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;aAC1B;QACF,CAAC,CAAC,CAAC;KACH;YAAS;QACT,UAAU,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,CAAC;QACpD,SAAS,CAAC,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE,CAC9B,QAAQ,CAAC,cAAc,CAAC,OAAO,EAAE,OAAO,IAAI,IAAI,CAAC,CACjD,CAAC;KACF;AACF,CAAC;AAvCD,0CAuCC"}
package/lib/index.ts CHANGED
@@ -14,7 +14,6 @@
14
14
  * See the License for the specific language governing permissions and
15
15
  * limitations under the License.
16
16
  */
17
- import * as Bluebird from 'bluebird';
18
17
  import * as path from 'path';
19
18
  import { Readable, Writable } from 'stream';
20
19
  import * as tar from 'tar-stream';
@@ -53,23 +52,24 @@ export function normalizeTarEntry(name: string): string {
53
52
  * streamToBuffer: Given a stream, read it into a buffer
54
53
  * @param stream
55
54
  */
56
- export function streamToBuffer(stream: Readable): Bluebird<Buffer> {
57
- let onData: (data: Buffer) => void;
58
- let onError: (error: Error) => void;
59
- let onEnd: () => void;
60
- return new Bluebird<Buffer[]>((resolve, reject) => {
61
- const chunks: Buffer[] = [];
62
- stream.on('end', (onEnd = () => resolve(chunks)));
63
- stream.on('error', (onError = reject));
64
- // adding a 'data' listener switches the stream to flowing mode
65
- stream.on('data', (onData = (data: Buffer) => chunks.push(data)));
66
- })
67
- .then(Buffer.concat)
68
- .finally(() => {
69
- stream.removeListener('data', onData || noop);
70
- stream.removeListener('error', onError || noop);
71
- stream.removeListener('end', onEnd || noop);
55
+ export async function streamToBuffer(stream: Readable): Promise<Buffer> {
56
+ let onData: ((data: Buffer) => void) | undefined;
57
+ let onError: ((error: Error) => void) | undefined;
58
+ let onEnd: (() => void) | undefined;
59
+ try {
60
+ const buffers = await new Promise<Buffer[]>((resolve, reject) => {
61
+ const chunks: Buffer[] = [];
62
+ stream.on('end', (onEnd = () => resolve(chunks)));
63
+ stream.on('error', (onError = reject));
64
+ // adding a 'data' listener switches the stream to flowing mode
65
+ stream.on('data', (onData = (data: Buffer) => chunks.push(data)));
72
66
  });
67
+ return Buffer.concat(buffers);
68
+ } finally {
69
+ stream.removeListener('data', onData ?? noop);
70
+ stream.removeListener('error', onError ?? noop);
71
+ stream.removeListener('end', onEnd ?? noop);
72
+ }
73
73
  }
74
74
 
75
75
  /**
@@ -80,17 +80,19 @@ export function streamToBuffer(stream: Readable): Bluebird<Buffer> {
80
80
  * @param stream A readable stream to be drained
81
81
  * @return A promise that resolves when the stream is drained
82
82
  */
83
- export function drainStream(stream: Readable): Bluebird<void> {
84
- let onError: (error: Error) => void;
85
- let onEnd: () => void;
86
- return new Bluebird<void>((resolve, reject) => {
87
- stream.on('error', (onError = reject));
88
- stream.on('end', (onEnd = resolve));
89
- stream.resume();
90
- }).finally(() => {
91
- stream.removeListener('error', onError || noop);
92
- stream.removeListener('end', onEnd || noop);
93
- });
83
+ export async function drainStream(stream: Readable): Promise<void> {
84
+ let onError: ((error: Error) => void) | undefined;
85
+ let onEnd: (() => void) | undefined;
86
+ try {
87
+ return await new Promise<void>((resolve, reject) => {
88
+ stream.on('error', (onError = reject));
89
+ stream.on('end', (onEnd = resolve));
90
+ stream.resume();
91
+ });
92
+ } finally {
93
+ stream.removeListener('error', onError ?? noop);
94
+ stream.removeListener('end', onEnd ?? noop);
95
+ }
94
96
  }
95
97
 
96
98
  /**
@@ -103,22 +105,24 @@ export function drainStream(stream: Readable): Bluebird<void> {
103
105
  * @param pipeFrom Stream to pipe from
104
106
  * @param pipeTo Stream to pipe to
105
107
  */
106
- export function pipePromise<WritableSub extends Writable>(
108
+ export async function pipePromise<WritableSub extends Writable>(
107
109
  pipeFrom: Readable,
108
110
  pipeTo: WritableSub,
109
- ): Bluebird<WritableSub> {
110
- let onError: (error: Error) => void;
111
- let onFinish: () => void;
112
- return new Bluebird<WritableSub>((resolve, reject) => {
113
- pipeFrom.on('error', (onError = reject));
114
- pipeTo.on('error', onError);
115
- pipeTo.on('finish', (onFinish = () => resolve(pipeTo)));
116
- pipeFrom.pipe(pipeTo);
117
- }).finally(() => {
118
- pipeFrom.removeListener('error', onError || noop);
119
- pipeTo.removeListener('error', onError || noop);
120
- pipeTo.removeListener('finish', onFinish || noop);
121
- });
111
+ ): Promise<WritableSub> {
112
+ let onError: ((error: Error) => void) | undefined;
113
+ let onFinish: (() => void) | undefined;
114
+ try {
115
+ return await new Promise<WritableSub>((resolve, reject) => {
116
+ pipeFrom.on('error', (onError = reject));
117
+ pipeTo.on('error', onError);
118
+ pipeTo.on('finish', (onFinish = () => resolve(pipeTo)));
119
+ pipeFrom.pipe(pipeTo);
120
+ });
121
+ } finally {
122
+ pipeFrom.removeListener('error', onError ?? noop);
123
+ pipeTo.removeListener('error', onError ?? noop);
124
+ pipeTo.removeListener('finish', onFinish ?? noop);
125
+ }
122
126
  }
123
127
 
124
128
  /**
@@ -135,62 +139,72 @@ export function pipePromise<WritableSub extends Writable>(
135
139
  * the caller to insert additional tar entries. onFinish may return a
136
140
  * promise which will then be awaited for.
137
141
  */
138
- export function cloneTarStream(
142
+ export async function cloneTarStream(
139
143
  sourceTarStream: Readable,
140
144
  opts?: {
141
145
  onEntry?: (pack: tar.Pack, header: tar.Headers, stream: Readable) => void;
142
146
  onFinish?: (pack: tar.Pack) => void;
143
147
  },
144
- ): Bluebird<tar.Pack> {
148
+ ): Promise<tar.Pack> {
145
149
  const extract = tar.extract();
146
150
  const pack = tar.pack();
147
151
  const origPush = pack.push;
148
- pack.push = function() {
152
+ pack.push = function () {
149
153
  origPush.apply(this, arguments);
150
154
  // Disable backpressure as we want to buffer everything in memory in order to
151
155
  // ensure we trigger any listeners/etc that may be on the stream
152
156
  return true;
153
157
  };
154
- let packOnError: (error: Error) => void;
155
- let sourceTarStreamOnError: (error: Error) => void;
156
- return new Bluebird<tar.Pack>((resolve, reject) => {
157
- packOnError = reject;
158
- sourceTarStreamOnError = reject;
159
- sourceTarStream.on('error', sourceTarStreamOnError);
160
- pack.on('error', packOnError);
161
- extract.on('error', reject);
162
- extract.on(
163
- 'entry',
164
- (header: tar.Headers, stream: Readable, callback: tar.Callback) => {
165
- if (opts && opts.onEntry) {
166
- Bluebird.try(() => opts.onEntry!(pack, header, stream)).then(
167
- callback as () => void,
168
- callback,
169
- );
170
- } else {
171
- streamToBuffer(stream).then(buf => {
172
- pack.entry(header, buf, callback);
173
- });
174
- }
175
- },
176
- );
177
- extract.once('finish', () => {
178
- Bluebird.try(() => {
179
- if (opts && opts.onFinish) {
180
- return opts.onFinish(pack);
181
- }
182
- })
183
- .then(() => {
158
+ let packOnError: ((error: Error) => void) | undefined;
159
+ let sourceTarStreamOnError: ((error: Error) => void) | undefined;
160
+ try {
161
+ return await new Promise<tar.Pack>((resolve, reject) => {
162
+ packOnError = reject;
163
+ sourceTarStreamOnError = reject;
164
+ sourceTarStream.on('error', sourceTarStreamOnError);
165
+ pack.on('error', packOnError);
166
+ extract.on('error', reject);
167
+ extract.on(
168
+ 'entry',
169
+ async (
170
+ header: tar.Headers,
171
+ stream: Readable,
172
+ callback: tar.Callback,
173
+ ) => {
174
+ if (opts?.onEntry) {
175
+ try {
176
+ await opts.onEntry(pack, header, stream);
177
+ } catch (err) {
178
+ callback(err);
179
+ }
180
+ } else {
181
+ const buf = await streamToBuffer(stream);
182
+ if (header.type !== 'file' && header.type !== 'contiguous-file') {
183
+ // "void" entries are not allowed to pass in a buffer, even an empty one, as of tar-stream 3.1.5
184
+ pack.entry(header, callback);
185
+ } else {
186
+ pack.entry(header, buf, callback);
187
+ }
188
+ }
189
+ },
190
+ );
191
+ extract.once('finish', async () => {
192
+ try {
193
+ if (opts?.onFinish) {
194
+ await opts.onFinish(pack);
195
+ }
184
196
  pack.finalize();
185
197
  resolve(pack);
186
- })
187
- .catch(reject);
198
+ } catch (err) {
199
+ reject(err);
200
+ }
201
+ });
202
+ sourceTarStream.pipe(extract);
188
203
  });
189
- sourceTarStream.pipe(extract);
190
- }).finally(() => {
191
- sourceTarStream.removeListener('error', sourceTarStreamOnError || noop);
192
- pack.removeListener('error', packOnError || noop);
193
- });
204
+ } finally {
205
+ sourceTarStream.removeListener('error', sourceTarStreamOnError ?? noop);
206
+ pack.removeListener('error', packOnError ?? noop);
207
+ }
194
208
  }
195
209
 
196
210
  /**
@@ -205,41 +219,43 @@ export function cloneTarStream(
205
219
  * @param fromStream
206
220
  * @param toStreams
207
221
  */
208
- export function multicastStream(
222
+ export async function multicastStream(
209
223
  fromStream: Readable,
210
224
  toStreams: Writable[],
211
- ): Bluebird<void> {
225
+ ): Promise<void> {
212
226
  if (toStreams.length === 0) {
213
- return Bluebird.resolve();
227
+ return;
214
228
  }
215
- let onError: (error: Error) => void;
216
- return new Bluebird<void>((resolve, reject) => {
217
- // Note: there is a reason to use Bluebird.all instead of Bluebird.map
218
- // here. Bluebird.map defers execution of the mapper function to a
219
- // subsequent iteration of Node's event loop, which creates the
220
- // possibility that fromStream.pipe(toStream) is executed before
221
- // the 'finish' listener is added. By using toStreams.map(), it is
222
- // guaranteed that the 'finish' listener is added first.
223
- Bluebird.all(
224
- toStreams.map((toStream: Writable) => {
225
- let onFinish: () => void;
226
- return new Bluebird(toStreamResolve =>
227
- toStream.on('finish', (onFinish = toStreamResolve)),
228
- ).finally(() => toStream.removeListener('finish', onFinish || noop));
229
- }),
230
- )
231
- .then(() => resolve())
232
- .catch(reject);
229
+ let onError: ((error: Error) => void) | undefined;
230
+ try {
231
+ return await new Promise<void>((resolve, reject) => {
232
+ // Note: the 'finish' listener must be added before fromStream.pipe(toStream)
233
+ // is executed so the addition must be in a synchronous path
234
+ Promise.all(
235
+ toStreams.map(async (toStream: Writable) => {
236
+ let onFinish: (() => void) | undefined;
237
+ try {
238
+ return await new Promise<void>((toStreamResolve) =>
239
+ toStream.on('finish', (onFinish = toStreamResolve)),
240
+ );
241
+ } finally {
242
+ toStream.removeListener('finish', onFinish ?? noop);
243
+ }
244
+ }),
245
+ )
246
+ .then(() => resolve())
247
+ .catch(reject);
233
248
 
234
- fromStream.on('error', (onError = reject));
235
- for (const toStream of toStreams) {
236
- toStream.on('error', onError);
237
- fromStream.pipe(toStream);
238
- }
239
- }).finally(() => {
240
- fromStream.removeListener('error', onError || noop);
241
- toStreams.forEach(toStream =>
242
- toStream.removeListener('error', onError || noop),
249
+ fromStream.on('error', (onError = reject));
250
+ for (const toStream of toStreams) {
251
+ toStream.on('error', onError);
252
+ fromStream.pipe(toStream);
253
+ }
254
+ });
255
+ } finally {
256
+ fromStream.removeListener('error', onError ?? noop);
257
+ toStreams.forEach((toStream) =>
258
+ toStream.removeListener('error', onError ?? noop),
243
259
  );
244
- });
260
+ }
245
261
  }
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "tar-utils",
3
- "version": "2.1.3",
3
+ "version": "3.0.0",
4
4
  "description": "A collection of utilities which expose oft-used patterns when working with tar archives in node",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
7
7
  "scripts": {
8
- "test": "npm run lint && gulp test",
8
+ "test": "npm run lint && npx mocha",
9
9
  "lint": "balena-lint --typescript lib tests",
10
10
  "prettify": "balena-lint --typescript --fix lib tests",
11
11
  "prepublish": "require-npm4-to-publish",
@@ -22,26 +22,33 @@
22
22
  },
23
23
  "homepage": "https://github.com/resin-io-modules/node-tar-utils#readme",
24
24
  "dependencies": {
25
- "bluebird": "^3.7.2",
26
- "tar-stream": "^2.1.3"
25
+ "tar-stream": "^3.1.5"
27
26
  },
28
27
  "devDependencies": {
29
- "@balena/lint": "^4.1.1",
30
- "@types/bluebird": "^3.5.32",
31
- "@types/chai": "^3.5.2",
32
- "@types/mocha": "^2.2.41",
33
- "@types/node": "^10.17.28",
28
+ "@balena/lint": "^6.2.2",
29
+ "@types/chai": "^4.3.5",
30
+ "@types/mocha": "^10.0.1",
31
+ "@types/node": "^16.18.38",
34
32
  "@types/tar-stream": "^2.1.0",
35
- "chai": "^3.5.0",
36
- "gulp": "^4.0.2",
37
- "gulp-clean": "^0.3.2",
38
- "gulp-mocha": "^4.3.1",
39
- "gulp-sourcemap": "^1.0.1",
40
- "gulp-typescript": "^3.1.6",
41
- "gulp-util": "^3.0.8",
42
- "mocha": "^3.3.0",
33
+ "chai": "^4.3.7",
34
+ "mocha": "^10.2.0",
43
35
  "require-npm4-to-publish": "^1.0.0",
44
- "ts-node": "^7.0.1",
45
- "typescript": "^3.9.7"
36
+ "ts-node": "^10.9.1",
37
+ "typescript": "^5.1.6"
38
+ },
39
+ "mocha": {
40
+ "_": "tests",
41
+ "require": "ts-node/register/transpile-only",
42
+ "exit": true,
43
+ "extension": [
44
+ "ts",
45
+ "js"
46
+ ]
47
+ },
48
+ "engines": {
49
+ "node": ">=16.13.0"
50
+ },
51
+ "versionist": {
52
+ "publishedAt": "2023-07-05T13:07:24.075Z"
46
53
  }
47
54
  }
package/tests/tests.ts CHANGED
@@ -24,7 +24,7 @@ import * as tar from 'tar-stream';
24
24
  import * as TarUtils from '../lib';
25
25
 
26
26
  describe('Simple utils', () => {
27
- it('should correctly normalize a tar entry', done => {
27
+ it('should correctly normalize a tar entry', () => {
28
28
  const testCases = [
29
29
  // input, expected output
30
30
  // a slash is also programmatically appended to every input test case
@@ -60,43 +60,37 @@ describe('Simple utils', () => {
60
60
  `normalizeTarEntry('${input}') returned '${result}' expected '${expected}'`,
61
61
  );
62
62
  }
63
- done();
64
63
  });
65
64
 
66
- it('should read a stream to a buffer', done => {
65
+ it('should read a stream to a buffer', async () => {
67
66
  const readable = new PassThrough();
68
67
 
69
68
  readable.write('test-string');
70
69
  readable.end();
71
70
 
72
- TarUtils.streamToBuffer(readable)
73
- .then(buf => {
74
- expect(buf.toString()).to.equal('test-string');
75
- done();
76
- })
77
- .catch(done);
71
+ const buf = await TarUtils.streamToBuffer(readable);
72
+ expect(buf.toString()).to.equal('test-string');
78
73
  });
79
74
  });
80
75
 
81
- describe('pipeStream', function() {
76
+ describe('pipeStream', function () {
82
77
  const hwm = 16333; // high water mark
83
78
  const sourceBuf = Buffer.alloc(71000, '0123456789');
84
79
 
85
- it('should resolve when the pipe operation completes', () => {
80
+ it('should resolve when the pipe operation completes', async () => {
86
81
  const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
87
82
  const toStream = new MockWritable({ highWaterMark: hwm });
88
83
 
89
- return TarUtils.pipePromise(fromStream, toStream).then(() => {
90
- const destBuf = Buffer.concat(toStream.chunks);
91
- expect(sourceBuf.compare(destBuf)).to.equal(0);
92
- });
84
+ await TarUtils.pipePromise(fromStream, toStream);
85
+ const destBuf = Buffer.concat(toStream.chunks);
86
+ expect(sourceBuf.compare(destBuf)).to.equal(0);
93
87
  });
94
88
  });
95
89
 
96
- describe('cloneTarStream', function() {
90
+ describe('cloneTarStream', function () {
97
91
  const hwm = 16333; // high water mark
98
92
 
99
- it('should successfully clone a tar file', () => {
93
+ it('should successfully clone a tar file', async () => {
100
94
  const sourceTarStream = fs.createReadStream(
101
95
  './tests/test-files/cloneTarStream.tar',
102
96
  {
@@ -113,38 +107,37 @@ describe('cloneTarStream', function() {
113
107
  ['./aFolder/fileSizeZero', 0],
114
108
  ];
115
109
 
116
- return TarUtils.cloneTarStream(sourceTarStream).then((pack: tar.Pack) => {
117
- return new Bluebird((resolve, reject) => {
118
- let i = 0;
119
- const extract = tar.extract();
120
- pack.on('error', reject);
121
- extract.on('error', reject);
122
- extract.on(
123
- 'entry',
124
- (header: tar.Headers, stream: Readable, callback: () => void) => {
125
- try {
126
- const [expectedName, expectedSize] = expectedEntries[i++];
127
- expect(header.name).to.equal(expectedName);
128
- expect(header.size).to.equal(expectedSize);
129
- } catch (error) {
130
- reject(error);
131
- }
132
- TarUtils.drainStream(stream).then(callback, callback);
133
- },
134
- );
135
- extract.once('finish', resolve);
136
- pack.pipe(extract);
137
- });
110
+ const pack = await TarUtils.cloneTarStream(sourceTarStream);
111
+ await new Promise((resolve, reject) => {
112
+ let i = 0;
113
+ const extract = tar.extract();
114
+ pack.on('error', reject);
115
+ extract.on('error', reject);
116
+ extract.on(
117
+ 'entry',
118
+ (header: tar.Headers, stream: Readable, callback: () => void) => {
119
+ try {
120
+ const [expectedName, expectedSize] = expectedEntries[i++];
121
+ expect(header.name).to.equal(expectedName);
122
+ expect(header.size).to.equal(expectedSize);
123
+ } catch (error) {
124
+ reject(error);
125
+ }
126
+ TarUtils.drainStream(stream).then(callback, callback);
127
+ },
128
+ );
129
+ extract.once('finish', resolve);
130
+ pack.pipe(extract);
138
131
  });
139
132
  });
140
133
  });
141
134
 
142
- describe('multicastStream', function() {
135
+ describe('multicastStream', function () {
143
136
  this.timeout(60000);
144
137
  const sourceBuf = Buffer.alloc(71011, '0123456789');
145
138
  const hwm = 16384; // high water mark
146
139
 
147
- it('should successfully multicast a producer stream to different-pace consumers', () => {
140
+ it('should successfully multicast a producer stream to different-pace consumers', async () => {
148
141
  const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
149
142
  const toStreams: MockWritable[] = [];
150
143
  const nStreams = 3;
@@ -154,56 +147,53 @@ describe('multicastStream', function() {
154
147
  );
155
148
  }
156
149
 
157
- return TarUtils.multicastStream(fromStream, toStreams).then(() => {
158
- for (const toStream of toStreams) {
159
- const dest = Buffer.concat(toStream.chunks);
160
- expect(toStream.chunks.length).to.equal(
161
- Math.ceil(sourceBuf.length / hwm),
162
- );
163
- expect(sourceBuf.compare(dest)).to.equal(0);
164
- }
165
- });
150
+ await TarUtils.multicastStream(fromStream, toStreams);
151
+ for (const toStream of toStreams) {
152
+ const dest = Buffer.concat(toStream.chunks);
153
+ expect(toStream.chunks.length).to.equal(
154
+ Math.ceil(sourceBuf.length / hwm),
155
+ );
156
+ expect(sourceBuf.compare(dest)).to.equal(0);
157
+ }
166
158
  });
167
159
 
168
- it('should resolve for an empty list of destination streams', () => {
160
+ it('should resolve for an empty list of destination streams', async () => {
169
161
  const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
170
- return TarUtils.multicastStream(fromStream, []);
162
+ await TarUtils.multicastStream(fromStream, []);
171
163
  });
172
164
 
173
- it('should reject when a destination stream emits an error', () => {
165
+ it('should reject when a destination stream emits an error', async () => {
174
166
  const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf);
175
167
  const toStreams: MockWritable[] = [];
176
168
  const nStreams = 3;
177
169
  for (let i = 0; i < nStreams; ++i) {
178
170
  toStreams.push(new MockWritable({ highWaterMark: hwm }, 0, i + 1));
179
171
  }
180
- return TarUtils.multicastStream(fromStream, toStreams)
181
- .then(() => {
182
- throw new Error(
183
- 'multicastStream call should have rejected, but succeeded',
184
- );
185
- })
186
- .catch((error: Error) => {
187
- expect(error.message).to.equal('write count is 1');
188
- });
172
+ try {
173
+ await TarUtils.multicastStream(fromStream, toStreams);
174
+ throw new Error(
175
+ 'multicastStream call should have rejected, but succeeded',
176
+ );
177
+ } catch (error) {
178
+ expect(error.message).to.equal('write count is 1');
179
+ }
189
180
  });
190
181
 
191
- it('should reject when the source stream emits an error', () => {
182
+ it('should reject when the source stream emits an error', async () => {
192
183
  const fromStream = new MockReadable({ highWaterMark: hwm }, sourceBuf, 2);
193
184
  const toStreams: MockWritable[] = [];
194
185
  const nStreams = 3;
195
186
  for (let i = 0; i < nStreams; ++i) {
196
187
  toStreams.push(new MockWritable({ highWaterMark: hwm }, 0));
197
188
  }
198
- return TarUtils.multicastStream(fromStream, toStreams)
199
- .then(() => {
200
- throw new Error(
201
- 'multicastStream call should have rejected, but succeeded',
202
- );
203
- })
204
- .catch((error: Error) => {
205
- expect(error.message).to.equal('read count is 2');
206
- });
189
+ try {
190
+ await TarUtils.multicastStream(fromStream, toStreams);
191
+ throw new Error(
192
+ 'multicastStream call should have rejected, but succeeded',
193
+ );
194
+ } catch (error) {
195
+ expect(error.message).to.equal('read count is 2');
196
+ }
207
197
  });
208
198
  });
209
199
 
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "compilerOptions": {
3
3
  "module": "commonjs",
4
- "target": "es6",
4
+ "target": "es2021",
5
5
  "outDir": "build",
6
6
  "declaration": true,
7
7
  "noImplicitAny": true,
@@ -1,83 +0,0 @@
1
- version: 2
2
-
3
- buildSteps: &buildSteps
4
- - checkout
5
- - run:
6
- name: Install
7
- command: npm install --loglevel warn
8
- - run:
9
- name: Test
10
- command: npm test --loglevel warn
11
- - persist_to_workspace:
12
- # Persist all job output, so we can (potentially) use it for deploys
13
- root: ../
14
- paths:
15
- - ./node-*
16
-
17
- jobs:
18
- node-6:
19
- docker:
20
- - image: circleci/node:6
21
- working_directory: ~/node-6
22
- steps: *buildSteps
23
-
24
- node-8:
25
- docker:
26
- - image: circleci/node:8
27
- working_directory: ~/node-8
28
- steps: *buildSteps
29
-
30
- node-10:
31
- docker:
32
- - image: circleci/node:10
33
- working_directory: ~/node-10
34
- steps: *buildSteps
35
-
36
- deploy:
37
- # For this to work NPM_TOKEN must be set for the account used for publishing
38
- docker:
39
- - image: circleci/node:8
40
- steps:
41
- - attach_workspace:
42
- at: $CIRCLE_WORKING_DIRECTORY
43
- - run:
44
- name: Login
45
- command: |
46
- echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
47
- npm whoami
48
- - deploy:
49
- name: Deploy
50
- command: npm publish
51
- # Output used for publish is from node 8 build
52
- working_directory: $CIRCLE_WORKING_DIRECTORY/node-8
53
-
54
- workflows:
55
- version: 2
56
- build:
57
- jobs:
58
- - node-6:
59
- # Run for all tags (required to allow the deploy to trigger on version tags)
60
- filters:
61
- tags:
62
- only: /.*/
63
- - node-8:
64
- # Run for all tags (required to allow the deploy to trigger on version tags)
65
- filters:
66
- tags:
67
- only: /.*/
68
- - node-10:
69
- # Run for all tags (required to allow the deploy to trigger on version tags)
70
- filters:
71
- tags:
72
- only: /.*/
73
- - deploy:
74
- # Deploy passing builds if they're tagged with a version
75
- requires:
76
- - node-6
77
- - node-8
78
- - node-10
79
- filters:
80
- tags:
81
- only: /^v\d+\.\d+\.\d+$/
82
- branches:
83
- ignore: /.*/
package/gulpfile.js DELETED
@@ -1,43 +0,0 @@
1
- const gulp = require('gulp')
2
- const gutil = require('gulp-util')
3
- require('gulp-clean')
4
- const gmocha = require('gulp-mocha')
5
- const typescript = require('gulp-typescript')
6
- const sourcemaps = require('gulp-sourcemaps')
7
- require('ts-node/register/transpile-only')
8
- const tsProject = typescript.createProject('tsconfig.json')
9
-
10
- const OPTIONS = {
11
- dirs: {
12
- sources: './lib',
13
- build: './build'
14
- }
15
- }
16
-
17
- gulp.task('clean', () => {
18
- return gulp.src(OPTIONS.dirs.build, { read: false })
19
- })
20
-
21
- gulp.task('test', () =>
22
- gulp.src('tests/tests.ts')
23
- .pipe(gmocha({
24
- compilers: [
25
- 'ts:ts-node/register/transpile-only'
26
- ]
27
- }))
28
- )
29
-
30
- gulp.task('typescript', () =>
31
- tsProject.src()
32
- .pipe(sourcemaps.init())
33
- .pipe(tsProject()).on('error', gutil.log)
34
- .pipe(sourcemaps.write('./', {
35
- includeContent: true,
36
- sourceRoot: OPTIONS.dirs.sources,
37
- rootDir: '.'
38
- }))
39
- .pipe(gulp.dest(OPTIONS.dirs.build))
40
- )
41
-
42
- gulp.task('build', gulp.series('typescript'))
43
- gulp.task('default', gulp.series('build'))