@jungvonmatt/contentful-ssg 1.7.0 → 1.7.4

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/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import Listr from 'listr';
2
- import { BehaviorSubject } from 'rxjs';
2
+ import { ReplaySubject } from 'rxjs';
3
3
  import chalk from 'chalk';
4
4
  import { getContentTypeId, getContentId } from './lib/contentful.js';
5
5
  import { setup } from './tasks/setup.js';
@@ -64,7 +64,7 @@ export const run = async (config) => {
64
64
  const tasks = locales.map((locale) => ({
65
65
  title: `${locale.code}`,
66
66
  task: async () => {
67
- const subject = new BehaviorSubject(null);
67
+ const subject = new ReplaySubject();
68
68
  const observable = subject.asObservable();
69
69
  const data = ctx.localized.get(locale.code);
70
70
  const { entries = [] } = data || {};
package/dist/types.d.ts CHANGED
@@ -7,6 +7,7 @@ import type { ListrTaskObject } from 'listr';
7
7
  import type { FileManager } from './lib/file-manager.js';
8
8
  import type { Stats } from './lib/stats.js';
9
9
  import type { HookManager } from './lib/hook-manager.js';
10
+ export type { Ignore } from 'ignore';
10
11
  export declare type KeyValueMap<T = any> = Record<string, T>;
11
12
  export declare type Locale = ContentfulLocale;
12
13
  export declare type ContentType = ContentfulContentType;
@@ -152,12 +153,6 @@ export declare type TransformContext = LocalizedContent & {
152
153
  export declare type ObservableContext = Readonly<Pick<TransformContext, 'id' | 'contentTypeId' | 'entry' | 'content' | 'locale'> & {
153
154
  error?: Error;
154
155
  }>;
155
- export interface Ignore {
156
- add(pattern: string | Ignore | string[] | Ignore[]): Ignore;
157
- filter(paths: string[]): string[];
158
- createFilter(): (path: string) => boolean;
159
- ignores(pathname: string): boolean;
160
- }
161
156
  export interface StatsEntry extends KeyValueMap {
162
157
  id: string;
163
158
  contentTypeId: string;
@@ -201,4 +196,3 @@ export interface ErrorEntry {
201
196
  locale: Locale;
202
197
  missingFields: string[];
203
198
  }
204
- export {};
package/package.json CHANGED
@@ -1,7 +1,14 @@
1
1
  {
2
2
  "name": "@jungvonmatt/contentful-ssg",
3
- "version": "1.7.0",
3
+ "version": "1.7.4",
4
4
  "description": "",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/jungvonmatt/contentful-ssg.git"
8
+ },
9
+ "bugs": {
10
+ "url": "https://github.com/jungvonmatt/contentful-ssg/issues"
11
+ },
5
12
  "main": "./dist/index.js",
6
13
  "type": "module",
7
14
  "typings": "./dist/types.d.ts",
@@ -156,5 +163,5 @@
156
163
  "module": "es2020"
157
164
  }
158
165
  },
159
- "gitHead": "441c4188533375574d0bd461b3e043ba0c7d2655"
166
+ "gitHead": "d6529cec33cf6939f0cebf189437b6e65e6be7b4"
160
167
  }
package/src/index.ts CHANGED
@@ -7,7 +7,7 @@ import type {
7
7
  TransformHelper,
8
8
  } from './types.js';
9
9
  import Listr from 'listr';
10
- import { BehaviorSubject } from 'rxjs';
10
+ import { ReplaySubject } from 'rxjs';
11
11
  import chalk from 'chalk';
12
12
  import { getContentTypeId, getContentId } from './lib/contentful.js';
13
13
  import { setup } from './tasks/setup.js';
@@ -91,7 +91,7 @@ export const run = async (config: Config): Promise<void> => {
91
91
  const tasks = locales.map((locale) => ({
92
92
  title: `${locale.code}`,
93
93
  task: async () => {
94
- const subject = new BehaviorSubject<ObservableContext>(null);
94
+ const subject = new ReplaySubject<ObservableContext>();
95
95
  const observable = subject.asObservable();
96
96
  const data = ctx.localized.get(locale.code);
97
97
  const { entries = [] } = data || {};
@@ -1,6 +1,6 @@
1
1
  import { Entry, TransformContext } from '../types.js';
2
2
  import { collect, collectParentValues, collectValues, waitFor } from './utils.js';
3
- import { BehaviorSubject } from 'rxjs';
3
+ import { ReplaySubject } from 'rxjs';
4
4
  import { WrappedError } from './error.js';
5
5
 
6
6
  const data = new Map([
@@ -140,7 +140,7 @@ describe('Utils', () => {
140
140
  });
141
141
 
142
142
  test('waitFor', async () => {
143
- const subject = new BehaviorSubject<TransformContext>(null);
143
+ const subject = new ReplaySubject<TransformContext>(null);
144
144
  const observable = subject.asObservable();
145
145
 
146
146
  // Throw error when waiting for the current entry
@@ -168,7 +168,7 @@ describe('Utils', () => {
168
168
  });
169
169
 
170
170
  test('waitFor error', async () => {
171
- const subject = new BehaviorSubject<TransformContext>(null);
171
+ const subject = new ReplaySubject<TransformContext>(null);
172
172
  const observable = subject.asObservable();
173
173
  const entry = entryMap.get('3');
174
174
 
@@ -196,7 +196,7 @@ describe('Utils', () => {
196
196
  });
197
197
 
198
198
  test('detect cyclic dependency', async () => {
199
- const subject = new BehaviorSubject<TransformContext>(null);
199
+ const subject = new ReplaySubject<TransformContext>(null);
200
200
  const observable = subject.asObservable();
201
201
 
202
202
  // let 9 finish regularly
@@ -244,4 +244,55 @@ describe('Utils', () => {
244
244
  expect(result[3]).toMatch(/Awaited entry 6 \(test-type\) errored/);
245
245
  expect(result[4]).toMatch('SUCCESS 3');
246
246
  });
247
+
248
+ test('handle subscriptions on postponed subscribe', async () => {
249
+ const subject = new ReplaySubject<TransformContext>();
250
+ const observable = subject.asObservable();
251
+
252
+ const finishSuccess = (id, time = 0) =>
253
+ setTimeout(() => {
254
+ subject.next({
255
+ ...transformContext,
256
+ entry: entryMap.get(id),
257
+ observable,
258
+ });
259
+ }, time);
260
+
261
+ const finishError = (id, time = 0) =>
262
+ setTimeout(() => {
263
+ subject.next({
264
+ ...transformContext,
265
+ entry: entryMap.get(id),
266
+ error: new Error(`Error on ${id}`),
267
+ observable,
268
+ });
269
+ }, time);
270
+
271
+ finishSuccess('2', 20);
272
+ finishSuccess('3', 40);
273
+ finishError('4', 30);
274
+ finishSuccess('5', 50);
275
+
276
+ const transFormMock = () =>
277
+ Promise.all([
278
+ waitFor({ ...transformContext, entry: entryMap.get('1'), observable })('2'),
279
+ waitFor({ ...transformContext, entry: entryMap.get('1'), observable })('3'),
280
+ waitFor({ ...transformContext, entry: entryMap.get('1'), observable })('4'),
281
+ waitFor({ ...transformContext, entry: entryMap.get('1'), observable })('5'),
282
+ ]);
283
+
284
+ const result = await new Promise((resolve) => {
285
+ setTimeout(async () => {
286
+ try {
287
+ const result = await transFormMock();
288
+ resolve(result);
289
+ } catch (error) {
290
+ resolve(error);
291
+ }
292
+ }, 500);
293
+ });
294
+
295
+ expect(result).toBeInstanceOf(WrappedError);
296
+ expect((result as WrappedError).message).toMatch(/Awaited entry 4 \(test-type\) errored/);
297
+ });
247
298
  });
package/src/types.ts CHANGED
@@ -17,6 +17,8 @@ import type { FileManager } from './lib/file-manager.js';
17
17
  import type { Stats } from './lib/stats.js';
18
18
  import type { HookManager } from './lib/hook-manager.js';
19
19
 
20
+ export type { Ignore } from 'ignore';
21
+
20
22
  export type KeyValueMap<T = any> = Record<string, T>;
21
23
 
22
24
  export type Locale = ContentfulLocale;
@@ -227,12 +229,6 @@ export type ObservableContext = Readonly<
227
229
  error?: Error;
228
230
  }
229
231
  >;
230
- export interface Ignore {
231
- add(pattern: string | Ignore | string[] | Ignore[]): Ignore;
232
- filter(paths: string[]): string[];
233
- createFilter(): (path: string) => boolean;
234
- ignores(pathname: string): boolean;
235
- }
236
232
 
237
233
  export interface StatsEntry extends KeyValueMap {
238
234
  id: string;