@riebeckite/plugin-rename 0.0.22 → 0.0.24

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.
Files changed (2) hide show
  1. package/dist/index.js +48 -19
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1,6 +1,7 @@
1
1
  // index.ts
2
2
  import {
3
- definePlugin
3
+ definePlugin,
4
+ fingerprintExternalValue
4
5
  } from "@riebeckite/core";
5
6
 
6
7
  // src/lock.ts
@@ -208,7 +209,6 @@ function isRecord(value) {
208
209
  var PLUGIN_NAME = "rename";
209
210
  var LOCK_KEY = "routes.lock";
210
211
  var CACHE_VERSION = "1";
211
- var LOCK_MESSAGE = "Rename plugin: route lock could not be used; starting from an empty lock.";
212
212
  function renamePlugin(options = {}) {
213
213
  const enabled = options.enabled ?? true;
214
214
  const status = options.status ?? 308;
@@ -226,12 +226,52 @@ function renamePlugin(options = {}) {
226
226
  options,
227
227
  cacheVersion: CACHE_VERSION,
228
228
  enabled,
229
+ resolveExternalDependencies: async ({ cache }) => {
230
+ if (!enabled) return [];
231
+ try {
232
+ const raw = await cache.get(LOCK_KEY);
233
+ const lock = raw === void 0 ? emptyRouteLock() : parseRouteLock(raw);
234
+ if (!lock) {
235
+ return [
236
+ {
237
+ kind: "unavailable",
238
+ failure: {
239
+ id: "rename:routes-lock",
240
+ reason: "Route lock is invalid."
241
+ }
242
+ }
243
+ ];
244
+ }
245
+ return [
246
+ {
247
+ kind: "resolved",
248
+ snapshot: {
249
+ id: "rename:routes-lock",
250
+ fingerprint: fingerprintExternalValue(lock),
251
+ scope: { type: "all" },
252
+ value: lock
253
+ }
254
+ }
255
+ ];
256
+ } catch (error) {
257
+ return [
258
+ {
259
+ kind: "unavailable",
260
+ failure: {
261
+ id: "rename:routes-lock",
262
+ reason: messageOf(error)
263
+ }
264
+ }
265
+ ];
266
+ }
267
+ },
229
268
  onManifestCreated: async ({
230
269
  manifest,
231
270
  config,
232
271
  cache,
233
272
  diagnostics,
234
- logger
273
+ logger,
274
+ externalDependencies
235
275
  }) => {
236
276
  if (!enabled) return;
237
277
  if (!config) {
@@ -240,7 +280,8 @@ function renamePlugin(options = {}) {
240
280
  );
241
281
  return;
242
282
  }
243
- const previous = await readLock(cache, logger);
283
+ const previous = externalDependencies?.get("rename:routes-lock")?.value;
284
+ if (!isRouteLock(previous)) return;
244
285
  const current = buildRouteLock(manifest.publicEntries);
245
286
  const result = diffRoutes(previous, current, {
246
287
  status,
@@ -255,21 +296,6 @@ function renamePlugin(options = {}) {
255
296
  });
256
297
  }
257
298
  var rename = renamePlugin;
258
- async function readLock(cache, logger) {
259
- try {
260
- const raw = await cache.get(LOCK_KEY);
261
- if (raw === void 0) return emptyRouteLock();
262
- const parsed = parseRouteLock(raw);
263
- if (!parsed) {
264
- logger.warn(LOCK_MESSAGE, { key: LOCK_KEY });
265
- return emptyRouteLock();
266
- }
267
- return parsed;
268
- } catch (error) {
269
- logger.warn(LOCK_MESSAGE, { key: LOCK_KEY, error: messageOf(error) });
270
- return emptyRouteLock();
271
- }
272
- }
273
299
  async function writeLock(cache, lock, logger) {
274
300
  try {
275
301
  await cache.set(LOCK_KEY, lock);
@@ -280,6 +306,9 @@ async function writeLock(cache, lock, logger) {
280
306
  });
281
307
  }
282
308
  }
309
+ function isRouteLock(value) {
310
+ return parseRouteLock(value) !== null;
311
+ }
283
312
  function renameDiagnostic(diagnostic) {
284
313
  return { pluginName: PLUGIN_NAME, ...diagnostic };
285
314
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@riebeckite/plugin-rename",
3
- "version": "0.0.22",
3
+ "version": "0.0.24",
4
4
  "license": "Apache-2.0",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -14,7 +14,7 @@
14
14
  }
15
15
  },
16
16
  "dependencies": {
17
- "@riebeckite/core": "0.0.22"
17
+ "@riebeckite/core": "0.0.24"
18
18
  },
19
19
  "devDependencies": {
20
20
  "tsx": "^4.22.4"