@unhead/addons 1.11.14 → 1.11.15

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.
@@ -4,6 +4,7 @@ import { createUnplugin } from 'unplugin';
4
4
  import { transform } from 'unplugin-ast';
5
5
  import { createContext, runInContext } from 'node:vm';
6
6
  import { resolveMetaKeyType, resolveMetaKeyValue, resolvePackedMetaObjectValue } from '@unhead/shared';
7
+ import { walk } from 'estree-walker';
7
8
  import MagicString from 'magic-string';
8
9
  import { findStaticImports, parseStaticImport } from 'mlly';
9
10
 
@@ -75,238 +76,6 @@ const TreeshakeServerComposables = createUnplugin((options = {}) => {
75
76
  };
76
77
  });
77
78
 
78
- /**
79
- * @typedef { import('estree').Node} Node
80
- * @typedef {{
81
- * skip: () => void;
82
- * remove: () => void;
83
- * replace: (node: Node) => void;
84
- * }} WalkerContext
85
- */
86
-
87
- class WalkerBase {
88
- constructor() {
89
- /** @type {boolean} */
90
- this.should_skip = false;
91
-
92
- /** @type {boolean} */
93
- this.should_remove = false;
94
-
95
- /** @type {Node | null} */
96
- this.replacement = null;
97
-
98
- /** @type {WalkerContext} */
99
- this.context = {
100
- skip: () => (this.should_skip = true),
101
- remove: () => (this.should_remove = true),
102
- replace: (node) => (this.replacement = node)
103
- };
104
- }
105
-
106
- /**
107
- * @template {Node} Parent
108
- * @param {Parent | null | undefined} parent
109
- * @param {keyof Parent | null | undefined} prop
110
- * @param {number | null | undefined} index
111
- * @param {Node} node
112
- */
113
- replace(parent, prop, index, node) {
114
- if (parent && prop) {
115
- if (index != null) {
116
- /** @type {Array<Node>} */ (parent[prop])[index] = node;
117
- } else {
118
- /** @type {Node} */ (parent[prop]) = node;
119
- }
120
- }
121
- }
122
-
123
- /**
124
- * @template {Node} Parent
125
- * @param {Parent | null | undefined} parent
126
- * @param {keyof Parent | null | undefined} prop
127
- * @param {number | null | undefined} index
128
- */
129
- remove(parent, prop, index) {
130
- if (parent && prop) {
131
- if (index !== null && index !== undefined) {
132
- /** @type {Array<Node>} */ (parent[prop]).splice(index, 1);
133
- } else {
134
- delete parent[prop];
135
- }
136
- }
137
- }
138
- }
139
-
140
- /**
141
- * @typedef { import('estree').Node} Node
142
- * @typedef { import('./walker.js').WalkerContext} WalkerContext
143
- * @typedef {(
144
- * this: WalkerContext,
145
- * node: Node,
146
- * parent: Node | null,
147
- * key: string | number | symbol | null | undefined,
148
- * index: number | null | undefined
149
- * ) => void} SyncHandler
150
- */
151
-
152
- class SyncWalker extends WalkerBase {
153
- /**
154
- *
155
- * @param {SyncHandler} [enter]
156
- * @param {SyncHandler} [leave]
157
- */
158
- constructor(enter, leave) {
159
- super();
160
-
161
- /** @type {boolean} */
162
- this.should_skip = false;
163
-
164
- /** @type {boolean} */
165
- this.should_remove = false;
166
-
167
- /** @type {Node | null} */
168
- this.replacement = null;
169
-
170
- /** @type {WalkerContext} */
171
- this.context = {
172
- skip: () => (this.should_skip = true),
173
- remove: () => (this.should_remove = true),
174
- replace: (node) => (this.replacement = node)
175
- };
176
-
177
- /** @type {SyncHandler | undefined} */
178
- this.enter = enter;
179
-
180
- /** @type {SyncHandler | undefined} */
181
- this.leave = leave;
182
- }
183
-
184
- /**
185
- * @template {Node} Parent
186
- * @param {Node} node
187
- * @param {Parent | null} parent
188
- * @param {keyof Parent} [prop]
189
- * @param {number | null} [index]
190
- * @returns {Node | null}
191
- */
192
- visit(node, parent, prop, index) {
193
- if (node) {
194
- if (this.enter) {
195
- const _should_skip = this.should_skip;
196
- const _should_remove = this.should_remove;
197
- const _replacement = this.replacement;
198
- this.should_skip = false;
199
- this.should_remove = false;
200
- this.replacement = null;
201
-
202
- this.enter.call(this.context, node, parent, prop, index);
203
-
204
- if (this.replacement) {
205
- node = this.replacement;
206
- this.replace(parent, prop, index, node);
207
- }
208
-
209
- if (this.should_remove) {
210
- this.remove(parent, prop, index);
211
- }
212
-
213
- const skipped = this.should_skip;
214
- const removed = this.should_remove;
215
-
216
- this.should_skip = _should_skip;
217
- this.should_remove = _should_remove;
218
- this.replacement = _replacement;
219
-
220
- if (skipped) return node;
221
- if (removed) return null;
222
- }
223
-
224
- /** @type {keyof Node} */
225
- let key;
226
-
227
- for (key in node) {
228
- /** @type {unknown} */
229
- const value = node[key];
230
-
231
- if (value && typeof value === 'object') {
232
- if (Array.isArray(value)) {
233
- const nodes = /** @type {Array<unknown>} */ (value);
234
- for (let i = 0; i < nodes.length; i += 1) {
235
- const item = nodes[i];
236
- if (isNode(item)) {
237
- if (!this.visit(item, node, key, i)) {
238
- // removed
239
- i--;
240
- }
241
- }
242
- }
243
- } else if (isNode(value)) {
244
- this.visit(value, node, key, null);
245
- }
246
- }
247
- }
248
-
249
- if (this.leave) {
250
- const _replacement = this.replacement;
251
- const _should_remove = this.should_remove;
252
- this.replacement = null;
253
- this.should_remove = false;
254
-
255
- this.leave.call(this.context, node, parent, prop, index);
256
-
257
- if (this.replacement) {
258
- node = this.replacement;
259
- this.replace(parent, prop, index, node);
260
- }
261
-
262
- if (this.should_remove) {
263
- this.remove(parent, prop, index);
264
- }
265
-
266
- const removed = this.should_remove;
267
-
268
- this.replacement = _replacement;
269
- this.should_remove = _should_remove;
270
-
271
- if (removed) return null;
272
- }
273
- }
274
-
275
- return node;
276
- }
277
- }
278
-
279
- /**
280
- * Ducktype a node.
281
- *
282
- * @param {unknown} value
283
- * @returns {value is Node}
284
- */
285
- function isNode(value) {
286
- return (
287
- value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
288
- );
289
- }
290
-
291
- /**
292
- * @typedef {import('estree').Node} Node
293
- * @typedef {import('./sync.js').SyncHandler} SyncHandler
294
- * @typedef {import('./async.js').AsyncHandler} AsyncHandler
295
- */
296
-
297
- /**
298
- * @param {Node} ast
299
- * @param {{
300
- * enter?: SyncHandler
301
- * leave?: SyncHandler
302
- * }} walker
303
- * @returns {Node | null}
304
- */
305
- function walk(ast, { enter, leave }) {
306
- const instance = new SyncWalker(enter, leave);
307
- return instance.visit(ast, null);
308
- }
309
-
310
79
  const UseSeoMetaTransform = createUnplugin((options = {}) => {
311
80
  options.imports = options.imports || true;
312
81
  return {
@@ -6,6 +6,7 @@ const unplugin = require('unplugin');
6
6
  const unpluginAst = require('unplugin-ast');
7
7
  const node_vm = require('node:vm');
8
8
  const shared = require('@unhead/shared');
9
+ const estreeWalker = require('estree-walker');
9
10
  const MagicString = require('magic-string');
10
11
  const mlly = require('mlly');
11
12
 
@@ -81,238 +82,6 @@ const TreeshakeServerComposables = unplugin.createUnplugin((options = {}) => {
81
82
  };
82
83
  });
83
84
 
84
- /**
85
- * @typedef { import('estree').Node} Node
86
- * @typedef {{
87
- * skip: () => void;
88
- * remove: () => void;
89
- * replace: (node: Node) => void;
90
- * }} WalkerContext
91
- */
92
-
93
- class WalkerBase {
94
- constructor() {
95
- /** @type {boolean} */
96
- this.should_skip = false;
97
-
98
- /** @type {boolean} */
99
- this.should_remove = false;
100
-
101
- /** @type {Node | null} */
102
- this.replacement = null;
103
-
104
- /** @type {WalkerContext} */
105
- this.context = {
106
- skip: () => (this.should_skip = true),
107
- remove: () => (this.should_remove = true),
108
- replace: (node) => (this.replacement = node)
109
- };
110
- }
111
-
112
- /**
113
- * @template {Node} Parent
114
- * @param {Parent | null | undefined} parent
115
- * @param {keyof Parent | null | undefined} prop
116
- * @param {number | null | undefined} index
117
- * @param {Node} node
118
- */
119
- replace(parent, prop, index, node) {
120
- if (parent && prop) {
121
- if (index != null) {
122
- /** @type {Array<Node>} */ (parent[prop])[index] = node;
123
- } else {
124
- /** @type {Node} */ (parent[prop]) = node;
125
- }
126
- }
127
- }
128
-
129
- /**
130
- * @template {Node} Parent
131
- * @param {Parent | null | undefined} parent
132
- * @param {keyof Parent | null | undefined} prop
133
- * @param {number | null | undefined} index
134
- */
135
- remove(parent, prop, index) {
136
- if (parent && prop) {
137
- if (index !== null && index !== undefined) {
138
- /** @type {Array<Node>} */ (parent[prop]).splice(index, 1);
139
- } else {
140
- delete parent[prop];
141
- }
142
- }
143
- }
144
- }
145
-
146
- /**
147
- * @typedef { import('estree').Node} Node
148
- * @typedef { import('./walker.js').WalkerContext} WalkerContext
149
- * @typedef {(
150
- * this: WalkerContext,
151
- * node: Node,
152
- * parent: Node | null,
153
- * key: string | number | symbol | null | undefined,
154
- * index: number | null | undefined
155
- * ) => void} SyncHandler
156
- */
157
-
158
- class SyncWalker extends WalkerBase {
159
- /**
160
- *
161
- * @param {SyncHandler} [enter]
162
- * @param {SyncHandler} [leave]
163
- */
164
- constructor(enter, leave) {
165
- super();
166
-
167
- /** @type {boolean} */
168
- this.should_skip = false;
169
-
170
- /** @type {boolean} */
171
- this.should_remove = false;
172
-
173
- /** @type {Node | null} */
174
- this.replacement = null;
175
-
176
- /** @type {WalkerContext} */
177
- this.context = {
178
- skip: () => (this.should_skip = true),
179
- remove: () => (this.should_remove = true),
180
- replace: (node) => (this.replacement = node)
181
- };
182
-
183
- /** @type {SyncHandler | undefined} */
184
- this.enter = enter;
185
-
186
- /** @type {SyncHandler | undefined} */
187
- this.leave = leave;
188
- }
189
-
190
- /**
191
- * @template {Node} Parent
192
- * @param {Node} node
193
- * @param {Parent | null} parent
194
- * @param {keyof Parent} [prop]
195
- * @param {number | null} [index]
196
- * @returns {Node | null}
197
- */
198
- visit(node, parent, prop, index) {
199
- if (node) {
200
- if (this.enter) {
201
- const _should_skip = this.should_skip;
202
- const _should_remove = this.should_remove;
203
- const _replacement = this.replacement;
204
- this.should_skip = false;
205
- this.should_remove = false;
206
- this.replacement = null;
207
-
208
- this.enter.call(this.context, node, parent, prop, index);
209
-
210
- if (this.replacement) {
211
- node = this.replacement;
212
- this.replace(parent, prop, index, node);
213
- }
214
-
215
- if (this.should_remove) {
216
- this.remove(parent, prop, index);
217
- }
218
-
219
- const skipped = this.should_skip;
220
- const removed = this.should_remove;
221
-
222
- this.should_skip = _should_skip;
223
- this.should_remove = _should_remove;
224
- this.replacement = _replacement;
225
-
226
- if (skipped) return node;
227
- if (removed) return null;
228
- }
229
-
230
- /** @type {keyof Node} */
231
- let key;
232
-
233
- for (key in node) {
234
- /** @type {unknown} */
235
- const value = node[key];
236
-
237
- if (value && typeof value === 'object') {
238
- if (Array.isArray(value)) {
239
- const nodes = /** @type {Array<unknown>} */ (value);
240
- for (let i = 0; i < nodes.length; i += 1) {
241
- const item = nodes[i];
242
- if (isNode(item)) {
243
- if (!this.visit(item, node, key, i)) {
244
- // removed
245
- i--;
246
- }
247
- }
248
- }
249
- } else if (isNode(value)) {
250
- this.visit(value, node, key, null);
251
- }
252
- }
253
- }
254
-
255
- if (this.leave) {
256
- const _replacement = this.replacement;
257
- const _should_remove = this.should_remove;
258
- this.replacement = null;
259
- this.should_remove = false;
260
-
261
- this.leave.call(this.context, node, parent, prop, index);
262
-
263
- if (this.replacement) {
264
- node = this.replacement;
265
- this.replace(parent, prop, index, node);
266
- }
267
-
268
- if (this.should_remove) {
269
- this.remove(parent, prop, index);
270
- }
271
-
272
- const removed = this.should_remove;
273
-
274
- this.replacement = _replacement;
275
- this.should_remove = _should_remove;
276
-
277
- if (removed) return null;
278
- }
279
- }
280
-
281
- return node;
282
- }
283
- }
284
-
285
- /**
286
- * Ducktype a node.
287
- *
288
- * @param {unknown} value
289
- * @returns {value is Node}
290
- */
291
- function isNode(value) {
292
- return (
293
- value !== null && typeof value === 'object' && 'type' in value && typeof value.type === 'string'
294
- );
295
- }
296
-
297
- /**
298
- * @typedef {import('estree').Node} Node
299
- * @typedef {import('./sync.js').SyncHandler} SyncHandler
300
- * @typedef {import('./async.js').AsyncHandler} AsyncHandler
301
- */
302
-
303
- /**
304
- * @param {Node} ast
305
- * @param {{
306
- * enter?: SyncHandler
307
- * leave?: SyncHandler
308
- * }} walker
309
- * @returns {Node | null}
310
- */
311
- function walk(ast, { enter, leave }) {
312
- const instance = new SyncWalker(enter, leave);
313
- return instance.visit(ast, null);
314
- }
315
-
316
85
  const UseSeoMetaTransform = unplugin.createUnplugin((options = {}) => {
317
86
  options.imports = options.imports || true;
318
87
  return {
@@ -350,7 +119,7 @@ const UseSeoMetaTransform = unplugin.createUnplugin((options = {}) => {
350
119
  const ast = this.parse(code);
351
120
  const s = new MagicString__default(code);
352
121
  const extraImports = /* @__PURE__ */ new Set();
353
- walk(ast, {
122
+ estreeWalker.walk(ast, {
354
123
  enter(_node) {
355
124
  if (options.imports && _node.type === "ImportDeclaration" && packages.includes(_node.source.value)) {
356
125
  const node = _node;
package/dist/vite.cjs CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const UseSeoMetaTransform = require('./shared/addons.ec57f468.cjs');
3
+ const UseSeoMetaTransform = require('./shared/addons.CgcXPvGI.cjs');
4
4
  require('node:url');
5
5
  require('ufo');
6
6
  require('unplugin');
7
7
  require('unplugin-ast');
8
8
  require('node:vm');
9
9
  require('@unhead/shared');
10
+ require('estree-walker');
10
11
  require('magic-string');
11
12
  require('mlly');
12
13
 
package/dist/vite.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.cjs';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.cjs';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => Plugin[];
5
5
 
package/dist/vite.d.mts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.mjs';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.mjs';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => Plugin[];
5
5
 
package/dist/vite.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Plugin } from 'vite';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.js';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.js';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => Plugin[];
5
5
 
package/dist/vite.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.c17a6ac5.mjs';
1
+ import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.BBC86_qB.mjs';
2
2
  import 'node:url';
3
3
  import 'ufo';
4
4
  import 'unplugin';
5
5
  import 'unplugin-ast';
6
6
  import 'node:vm';
7
7
  import '@unhead/shared';
8
+ import 'estree-walker';
8
9
  import 'magic-string';
9
10
  import 'mlly';
10
11
 
package/dist/webpack.cjs CHANGED
@@ -1,12 +1,13 @@
1
1
  'use strict';
2
2
 
3
- const UseSeoMetaTransform = require('./shared/addons.ec57f468.cjs');
3
+ const UseSeoMetaTransform = require('./shared/addons.CgcXPvGI.cjs');
4
4
  require('node:url');
5
5
  require('ufo');
6
6
  require('unplugin');
7
7
  require('unplugin-ast');
8
8
  require('node:vm');
9
9
  require('@unhead/shared');
10
+ require('estree-walker');
10
11
  require('magic-string');
11
12
  require('mlly');
12
13
 
@@ -1,5 +1,5 @@
1
1
  import * as webpack from 'webpack';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.cjs';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.cjs';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
5
5
 
@@ -1,5 +1,5 @@
1
1
  import * as webpack from 'webpack';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.mjs';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.mjs';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
5
5
 
package/dist/webpack.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as webpack from 'webpack';
2
- import { U as UnpluginOptions } from './shared/addons.0f7fef83.js';
2
+ import { U as UnpluginOptions } from './shared/addons.Bh7ZeIPm.js';
3
3
 
4
4
  declare const _default: (options?: UnpluginOptions) => webpack.WebpackPluginInstance[];
5
5
 
package/dist/webpack.mjs CHANGED
@@ -1,10 +1,11 @@
1
- import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.c17a6ac5.mjs';
1
+ import { T as TreeshakeServerComposables, U as UseSeoMetaTransform } from './shared/addons.BBC86_qB.mjs';
2
2
  import 'node:url';
3
3
  import 'ufo';
4
4
  import 'unplugin';
5
5
  import 'unplugin-ast';
6
6
  import 'node:vm';
7
7
  import '@unhead/shared';
8
+ import 'estree-walker';
8
9
  import 'magic-string';
9
10
  import 'mlly';
10
11
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@unhead/addons",
3
3
  "type": "module",
4
- "version": "1.11.14",
4
+ "version": "1.11.15",
5
5
  "author": "Harlan Wilton <harlan@harlanzw.com>",
6
6
  "license": "MIT",
7
7
  "funding": "https://github.com/sponsors/harlan-zw",
@@ -49,18 +49,18 @@
49
49
  "dist"
50
50
  ],
51
51
  "dependencies": {
52
- "@rollup/pluginutils": "^5.1.3",
53
- "magic-string": "^0.30.14",
52
+ "@rollup/pluginutils": "^5.1.4",
53
+ "estree-walker": "^3.0.3",
54
+ "magic-string": "^0.30.17",
54
55
  "mlly": "^1.7.3",
55
56
  "ufo": "^1.5.4",
56
- "unplugin": "^1.16.0",
57
- "unplugin-ast": "^0.12.0",
58
- "@unhead/shared": "1.11.14",
59
- "@unhead/schema": "1.11.14"
57
+ "unplugin": "^2.1.2",
58
+ "unplugin-ast": "^0.13.1",
59
+ "@unhead/schema": "1.11.15",
60
+ "@unhead/shared": "1.11.15"
60
61
  },
61
62
  "devDependencies": {
62
- "@babel/types": "^7.26.3",
63
- "estree-walker": "^3.0.3"
63
+ "@babel/types": "^7.26.3"
64
64
  },
65
65
  "scripts": {
66
66
  "build": "unbuild .",