@cloudflare/vitest-pool-workers 0.16.3 → 0.16.5
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vitest-v3-to-v4.mjs","names":[],"sources":["../../src/codemods/vitest-v3-to-v4.ts"],"sourcesContent":["/**\n * jscodeshift codemod: migrate @cloudflare/vitest-pool-workers config from v3 to v4.\n *\n * Transforms:\n * import { defineWorkersProject } from \"@cloudflare/vitest-pool-workers/config\";\n * export default defineWorkersProject({ test: { poolOptions: { workers: { ... } } } });\n *\n * Into:\n * import { cloudflareTest } from \"@cloudflare/vitest-pool-workers\";\n * import { defineConfig } from \"vitest/config\";\n * export default defineConfig({ plugins: [cloudflareTest({ ... })], test: { ... } });\n *\n * Usage:\n * npx jscodeshift -t node_modules/@cloudflare/vitest-pool-workers/dist/codemods/vitest-v3-to-v4.mjs vitest.config.ts\n */\n\n// Minimal jscodeshift types — avoids requiring @types/jscodeshift as a dependency.\ninterface FileInfo {\n\tpath: string;\n\tsource: string;\n}\ninterface JSCodeshift {\n\t(source: string): Collection;\n\tImportDeclaration: ASTType;\n\tCallExpression: ASTType;\n\tObjectExpression: { check(node: unknown): node is ObjectExpressionNode };\n\tObjectProperty: { check(node: unknown): node is PropertyNode };\n\tProperty: { check(node: unknown): node is PropertyNode };\n\tIdentifier: { check(node: unknown): node is IdentifierNode };\n\tFunctionExpression: { check(node: unknown): boolean };\n\tArrowFunctionExpression: { check(node: unknown): boolean };\n\tArrayExpression: { check(node: unknown): node is ArrayExpressionNode };\n\timportDeclaration(\n\t\tspecifiers: ImportSpecifierNode[],\n\t\tsource: LiteralNode\n\t): ImportDeclarationNode;\n\timportSpecifier(\n\t\timported: IdentifierNode,\n\t\tlocal?: IdentifierNode\n\t): ImportSpecifierNode;\n\tidentifier(name: string): IdentifierNode;\n\tstringLiteral(value: string): LiteralNode;\n\tcallExpression(\n\t\tcallee: IdentifierNode,\n\t\targs: ExpressionNode[]\n\t): CallExpressionNode;\n\tarrayExpression(elements: ExpressionNode[]): ArrayExpressionNode;\n\tobjectProperty(key: IdentifierNode, value: ExpressionNode): PropertyNode;\n}\n\ninterface ASTType {\n\tname: string;\n}\n\ninterface ASTNode {\n\ttype: string;\n}\n\ninterface IdentifierNode extends ASTNode {\n\ttype: \"Identifier\";\n\tname: string;\n}\n\ninterface LiteralNode extends ASTNode {\n\tvalue: string;\n}\n\ninterface ImportSpecifierNode extends ASTNode {\n\ttype: \"ImportSpecifier\";\n\timported: IdentifierNode;\n\tlocal?: IdentifierNode;\n}\n\ninterface ImportDeclarationNode extends ASTNode {\n\ttype: \"ImportDeclaration\";\n\tsource: LiteralNode;\n\tspecifiers: ImportSpecifierNode[];\n}\n\ninterface PropertyNode extends ASTNode {\n\tkey: ASTNode;\n\tvalue: ASTNode;\n}\n\ninterface ObjectExpressionNode extends ASTNode {\n\ttype: \"ObjectExpression\";\n\tproperties: PropertyNode[];\n}\n\ninterface ArrayExpressionNode extends ASTNode {\n\ttype: \"ArrayExpression\";\n\telements: ExpressionNode[];\n}\n\ninterface CallExpressionNode extends ASTNode {\n\ttype: \"CallExpression\";\n\tcallee: ASTNode;\n\targuments: ASTNode[];\n}\n\ntype ExpressionNode = ASTNode;\n\ninterface NodePath<T = ASTNode> {\n\tnode: T;\n\tparent: NodePath;\n\tinsertAfter(node: ASTNode): void;\n}\n\ninterface Collection {\n\tfind(type: ASTType, filter?: Record<string, unknown>): Collection;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any\n\tforEach(callback: (path: NodePath<any>) => void): Collection;\n\tat(index: number): Collection;\n\tpaths(): NodePath[];\n\tlength: number;\n\ttoSource(): string;\n}\n\ninterface API {\n\tjscodeshift: JSCodeshift;\n}\n\nfunction isNamedProp(\n\tj: JSCodeshift,\n\tprop: ASTNode,\n\tname: string\n): prop is PropertyNode {\n\treturn (\n\t\t(j.Property.check(prop) || j.ObjectProperty.check(prop)) &&\n\t\tj.Identifier.check(prop.key) &&\n\t\t(prop.key as IdentifierNode).name === name\n\t);\n}\n\nfunction findNamedProp(\n\tj: JSCodeshift,\n\tproperties: PropertyNode[],\n\tname: string\n): PropertyNode | undefined {\n\treturn properties.find((prop) => isNamedProp(j, prop, name));\n}\n\nexport default function transform(fileInfo: FileInfo, api: API): string {\n\tconst j = api.jscodeshift;\n\tconst root = j(fileInfo.source);\n\n\t// 1. Find the import of @cloudflare/vitest-pool-workers/config with defineWorkersProject\n\tconst configImports = root.find(j.ImportDeclaration, {\n\t\tsource: { value: \"@cloudflare/vitest-pool-workers/config\" },\n\t});\n\n\tif (configImports.length === 0) {\n\t\t// Nothing to transform\n\t\treturn fileInfo.source;\n\t}\n\n\t// Update the import: change source and swap defineWorkersProject → cloudflareTest\n\tconfigImports.forEach((path: NodePath<ImportDeclarationNode>) => {\n\t\tpath.node.source.value = \"@cloudflare/vitest-pool-workers\";\n\t\tpath.node.specifiers = [\n\t\t\tj.importSpecifier(j.identifier(\"cloudflareTest\")),\n\t\t\t...(path.node.specifiers?.filter(\n\t\t\t\t(s) =>\n\t\t\t\t\t!(\n\t\t\t\t\t\ts.type === \"ImportSpecifier\" &&\n\t\t\t\t\t\ts.imported?.name === \"defineWorkersProject\"\n\t\t\t\t\t)\n\t\t\t) ?? []),\n\t\t];\n\t});\n\n\t// 2. Add `import { defineConfig } from \"vitest/config\"` after the last import\n\tconst allImports = root.find(j.ImportDeclaration);\n\tif (allImports.length > 0) {\n\t\tconst lastImport = allImports.at(-1);\n\t\tlastImport.forEach((path: NodePath) => {\n\t\t\tpath.insertAfter(\n\t\t\t\tj.importDeclaration(\n\t\t\t\t\t[j.importSpecifier(j.identifier(\"defineConfig\"))],\n\t\t\t\t\tj.stringLiteral(\"vitest/config\")\n\t\t\t\t)\n\t\t\t);\n\t\t});\n\t}\n\n\t// 3. Transform defineWorkersProject() → defineConfig() with plugins\n\troot\n\t\t.find(j.CallExpression, {\n\t\t\tcallee: { name: \"defineWorkersProject\" },\n\t\t})\n\t\t.forEach((path: NodePath<CallExpressionNode>) => {\n\t\t\t// Rename callee\n\t\t\t(path.node.callee as IdentifierNode).name = \"defineConfig\";\n\n\t\t\tconst config = path.node.arguments[0];\n\t\t\tif (!j.ObjectExpression.check(config)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"defineWorkersProject() is called with a function and not an object, \" +\n\t\t\t\t\t\t\"and so is too complex to apply a codemod to. \" +\n\t\t\t\t\t\t\"Please refer to the migration docs to perform the migration manually.\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Find test.poolOptions.workers\n\t\t\tconst testProp = findNamedProp(j, config.properties, \"test\");\n\t\t\tif (!testProp || !j.ObjectExpression.check(testProp.value)) {\n\t\t\t\tthrow new Error(\"Could not find `test` property in config\");\n\t\t\t}\n\t\t\tconst testObj = testProp.value as ObjectExpressionNode;\n\n\t\t\tconst poolOptionsProp = findNamedProp(\n\t\t\t\tj,\n\t\t\t\ttestObj.properties,\n\t\t\t\t\"poolOptions\"\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!poolOptionsProp ||\n\t\t\t\t!j.ObjectExpression.check(poolOptionsProp.value)\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Could not find `test.poolOptions` property in config\");\n\t\t\t}\n\t\t\tconst poolOptionsObj = poolOptionsProp.value as ObjectExpressionNode;\n\n\t\t\tconst workersProp = findNamedProp(\n\t\t\t\tj,\n\t\t\t\tpoolOptionsObj.properties,\n\t\t\t\t\"workers\"\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!workersProp ||\n\t\t\t\t!(\n\t\t\t\t\tj.ObjectExpression.check(workersProp.value) ||\n\t\t\t\t\tj.FunctionExpression.check(workersProp.value) ||\n\t\t\t\t\tj.ArrowFunctionExpression.check(workersProp.value)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Could not find `test.poolOptions.workers` property in config\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Create plugins: [cloudflareTest(<workers value>)]\n\t\t\tconst pluginCall = j.callExpression(j.identifier(\"cloudflareTest\"), [\n\t\t\t\tworkersProp.value as ExpressionNode,\n\t\t\t]);\n\n\t\t\tconst pluginsProp = findNamedProp(j, config.properties, \"plugins\");\n\t\t\tif (pluginsProp && j.ArrayExpression.check(pluginsProp.value)) {\n\t\t\t\t// Prepend to existing plugins array\n\t\t\t\t(pluginsProp.value as ArrayExpressionNode).elements.unshift(pluginCall);\n\t\t\t} else {\n\t\t\t\t// Create new plugins property at the start\n\t\t\t\tconfig.properties.unshift(\n\t\t\t\t\tj.objectProperty(\n\t\t\t\t\t\tj.identifier(\"plugins\"),\n\t\t\t\t\t\tj.arrayExpression([pluginCall])\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Remove poolOptions from test\n\t\t\ttestObj.properties = testObj.properties.filter(\n\t\t\t\t(prop) => !isNamedProp(j, prop, \"poolOptions\")\n\t\t\t);\n\t\t});\n\n\treturn root.toSource();\n}\n\n// Tell jscodeshift to use the TypeScript parser\nexport const parser = \"ts\";\n"],"mappings":";AA0HA,SAAS,YACR,GACA,MACA,MACuB;AACvB,SACE,EAAE,SAAS,MAAM,KAAK,IAAI,EAAE,eAAe,MAAM,KAAK,KACvD,EAAE,WAAW,MAAM,KAAK,IAAI,IAC3B,KAAK,IAAuB,SAAS;;AAIxC,SAAS,cACR,GACA,YACA,MAC2B;AAC3B,QAAO,WAAW,MAAM,SAAS,YAAY,GAAG,MAAM,KAAK,CAAC;;AAG7D,SAAwB,UAAU,UAAoB,KAAkB;CACvE,MAAM,IAAI,IAAI;CACd,MAAM,OAAO,EAAE,SAAS,OAAO;CAG/B,MAAM,gBAAgB,KAAK,KAAK,EAAE,mBAAmB,EACpD,QAAQ,EAAE,OAAO,0CAA0C,EAC3D,CAAC;AAEF,KAAI,cAAc,WAAW,EAE5B,QAAO,SAAS;AAIjB,eAAc,SAAS,SAA0C;AAChE,OAAK,KAAK,OA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+DACA;EAIF,MAAM,aAAa,EAAE,eAAe,EAAE,WAAW,iBAAiB,EAAE,CACnE,YAAY,MACZ,CAAC;EAEF,MAAM,cAAc,cAAc,GAAG,OAAO,YAAY,UAAU;AAClE,MAAI,eAAe,EAAE,gBAAgB,MAAM,YAAY,MAAM,CAE5D,CAAC,YAAY,MAA8B,SAAS,QAAQ,WAAW;MAGvE,QAAO,WAAW,QACjB,EAAE,eACD,EAAE,WAAW,UAAU,EACvB,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAC/B,CACD;AAIF,UAAQ,aAAa,QAAQ,WAAW,QACtC,SAAS,CAAC,YAAY,GAAG,MAAM,cAAc,CAC9C;GACA;AAEH,QAAO,KAAK,UAAU;;AAIvB,MAAa,SAAS"}
|
|
1
|
+
{"version":3,"file":"vitest-v3-to-v4.mjs","names":[],"sources":["../../src/codemods/vitest-v3-to-v4.ts"],"sourcesContent":["/**\n * jscodeshift codemod: migrate @cloudflare/vitest-pool-workers config from v3 to v4.\n *\n * Transforms:\n * import { defineWorkersProject } from \"@cloudflare/vitest-pool-workers/config\";\n * export default defineWorkersProject({ test: { poolOptions: { workers: { ... } } } });\n *\n * Into:\n * import { cloudflareTest } from \"@cloudflare/vitest-pool-workers\";\n * import { defineConfig } from \"vitest/config\";\n * export default defineConfig({ plugins: [cloudflareTest({ ... })], test: { ... } });\n *\n * Usage:\n * npx jscodeshift -t node_modules/@cloudflare/vitest-pool-workers/dist/codemods/vitest-v3-to-v4.mjs vitest.config.ts\n */\n\n// Minimal jscodeshift types — avoids requiring @types/jscodeshift as a dependency.\ninterface FileInfo {\n\tpath: string;\n\tsource: string;\n}\ninterface JSCodeshift {\n\t(source: string): Collection;\n\tImportDeclaration: ASTType;\n\tCallExpression: ASTType;\n\tObjectExpression: { check(node: unknown): node is ObjectExpressionNode };\n\tObjectProperty: { check(node: unknown): node is PropertyNode };\n\tProperty: { check(node: unknown): node is PropertyNode };\n\tIdentifier: { check(node: unknown): node is IdentifierNode };\n\tFunctionExpression: { check(node: unknown): boolean };\n\tArrowFunctionExpression: { check(node: unknown): boolean };\n\tArrayExpression: { check(node: unknown): node is ArrayExpressionNode };\n\timportDeclaration(\n\t\tspecifiers: ImportSpecifierNode[],\n\t\tsource: LiteralNode\n\t): ImportDeclarationNode;\n\timportSpecifier(\n\t\timported: IdentifierNode,\n\t\tlocal?: IdentifierNode\n\t): ImportSpecifierNode;\n\tidentifier(name: string): IdentifierNode;\n\tstringLiteral(value: string): LiteralNode;\n\tcallExpression(\n\t\tcallee: IdentifierNode,\n\t\targs: ExpressionNode[]\n\t): CallExpressionNode;\n\tarrayExpression(elements: ExpressionNode[]): ArrayExpressionNode;\n\tobjectProperty(key: IdentifierNode, value: ExpressionNode): PropertyNode;\n}\n\ninterface ASTType {\n\tname: string;\n}\n\ninterface ASTNode {\n\ttype: string;\n}\n\ninterface IdentifierNode extends ASTNode {\n\ttype: \"Identifier\";\n\tname: string;\n}\n\ninterface LiteralNode extends ASTNode {\n\tvalue: string;\n}\n\ninterface ImportSpecifierNode extends ASTNode {\n\ttype: \"ImportSpecifier\";\n\timported: IdentifierNode;\n\tlocal?: IdentifierNode;\n}\n\ninterface ImportDeclarationNode extends ASTNode {\n\ttype: \"ImportDeclaration\";\n\tsource: LiteralNode;\n\tspecifiers: ImportSpecifierNode[];\n}\n\ninterface PropertyNode extends ASTNode {\n\tkey: ASTNode;\n\tvalue: ASTNode;\n}\n\ninterface ObjectExpressionNode extends ASTNode {\n\ttype: \"ObjectExpression\";\n\tproperties: PropertyNode[];\n}\n\ninterface ArrayExpressionNode extends ASTNode {\n\ttype: \"ArrayExpression\";\n\telements: ExpressionNode[];\n}\n\ninterface CallExpressionNode extends ASTNode {\n\ttype: \"CallExpression\";\n\tcallee: ASTNode;\n\targuments: ASTNode[];\n}\n\ntype ExpressionNode = ASTNode;\n\ninterface NodePath<T = ASTNode> {\n\tnode: T;\n\tparent: NodePath;\n\tinsertAfter(node: ASTNode): void;\n}\n\ninterface Collection {\n\tfind(type: ASTType, filter?: Record<string, unknown>): Collection;\n\t// eslint-disable-next-line @typescript-eslint/no-explicit-any -- jscodeshift Collection.forEach accepts callbacks with narrowed NodePath types\n\tforEach(callback: (path: NodePath<any>) => void): Collection;\n\tat(index: number): Collection;\n\tpaths(): NodePath[];\n\tlength: number;\n\ttoSource(): string;\n}\n\ninterface API {\n\tjscodeshift: JSCodeshift;\n}\n\nfunction isNamedProp(\n\tj: JSCodeshift,\n\tprop: ASTNode,\n\tname: string\n): prop is PropertyNode {\n\treturn (\n\t\t(j.Property.check(prop) || j.ObjectProperty.check(prop)) &&\n\t\tj.Identifier.check(prop.key) &&\n\t\t(prop.key as IdentifierNode).name === name\n\t);\n}\n\nfunction findNamedProp(\n\tj: JSCodeshift,\n\tproperties: PropertyNode[],\n\tname: string\n): PropertyNode | undefined {\n\treturn properties.find((prop) => isNamedProp(j, prop, name));\n}\n\nexport default function transform(fileInfo: FileInfo, api: API): string {\n\tconst j = api.jscodeshift;\n\tconst root = j(fileInfo.source);\n\n\t// 1. Find the import of @cloudflare/vitest-pool-workers/config with defineWorkersProject\n\tconst configImports = root.find(j.ImportDeclaration, {\n\t\tsource: { value: \"@cloudflare/vitest-pool-workers/config\" },\n\t});\n\n\tif (configImports.length === 0) {\n\t\t// Nothing to transform\n\t\treturn fileInfo.source;\n\t}\n\n\t// Update the import: change source and swap defineWorkersProject → cloudflareTest\n\tconfigImports.forEach((path: NodePath<ImportDeclarationNode>) => {\n\t\tpath.node.source.value = \"@cloudflare/vitest-pool-workers\";\n\t\tpath.node.specifiers = [\n\t\t\tj.importSpecifier(j.identifier(\"cloudflareTest\")),\n\t\t\t...(path.node.specifiers?.filter(\n\t\t\t\t(s) =>\n\t\t\t\t\t!(\n\t\t\t\t\t\ts.type === \"ImportSpecifier\" &&\n\t\t\t\t\t\ts.imported?.name === \"defineWorkersProject\"\n\t\t\t\t\t)\n\t\t\t) ?? []),\n\t\t];\n\t});\n\n\t// 2. Add `import { defineConfig } from \"vitest/config\"` after the last import\n\tconst allImports = root.find(j.ImportDeclaration);\n\tif (allImports.length > 0) {\n\t\tconst lastImport = allImports.at(-1);\n\t\tlastImport.forEach((path: NodePath) => {\n\t\t\tpath.insertAfter(\n\t\t\t\tj.importDeclaration(\n\t\t\t\t\t[j.importSpecifier(j.identifier(\"defineConfig\"))],\n\t\t\t\t\tj.stringLiteral(\"vitest/config\")\n\t\t\t\t)\n\t\t\t);\n\t\t});\n\t}\n\n\t// 3. Transform defineWorkersProject() → defineConfig() with plugins\n\troot\n\t\t.find(j.CallExpression, {\n\t\t\tcallee: { name: \"defineWorkersProject\" },\n\t\t})\n\t\t.forEach((path: NodePath<CallExpressionNode>) => {\n\t\t\t// Rename callee\n\t\t\t(path.node.callee as IdentifierNode).name = \"defineConfig\";\n\n\t\t\tconst config = path.node.arguments[0];\n\t\t\tif (!j.ObjectExpression.check(config)) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"defineWorkersProject() is called with a function and not an object, \" +\n\t\t\t\t\t\t\"and so is too complex to apply a codemod to. \" +\n\t\t\t\t\t\t\"Please refer to the migration docs to perform the migration manually.\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Find test.poolOptions.workers\n\t\t\tconst testProp = findNamedProp(j, config.properties, \"test\");\n\t\t\tif (!testProp || !j.ObjectExpression.check(testProp.value)) {\n\t\t\t\tthrow new Error(\"Could not find `test` property in config\");\n\t\t\t}\n\t\t\tconst testObj = testProp.value as ObjectExpressionNode;\n\n\t\t\tconst poolOptionsProp = findNamedProp(\n\t\t\t\tj,\n\t\t\t\ttestObj.properties,\n\t\t\t\t\"poolOptions\"\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!poolOptionsProp ||\n\t\t\t\t!j.ObjectExpression.check(poolOptionsProp.value)\n\t\t\t) {\n\t\t\t\tthrow new Error(\"Could not find `test.poolOptions` property in config\");\n\t\t\t}\n\t\t\tconst poolOptionsObj = poolOptionsProp.value as ObjectExpressionNode;\n\n\t\t\tconst workersProp = findNamedProp(\n\t\t\t\tj,\n\t\t\t\tpoolOptionsObj.properties,\n\t\t\t\t\"workers\"\n\t\t\t);\n\t\t\tif (\n\t\t\t\t!workersProp ||\n\t\t\t\t!(\n\t\t\t\t\tj.ObjectExpression.check(workersProp.value) ||\n\t\t\t\t\tj.FunctionExpression.check(workersProp.value) ||\n\t\t\t\t\tj.ArrowFunctionExpression.check(workersProp.value)\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t\"Could not find `test.poolOptions.workers` property in config\"\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Create plugins: [cloudflareTest(<workers value>)]\n\t\t\tconst pluginCall = j.callExpression(j.identifier(\"cloudflareTest\"), [\n\t\t\t\tworkersProp.value as ExpressionNode,\n\t\t\t]);\n\n\t\t\tconst pluginsProp = findNamedProp(j, config.properties, \"plugins\");\n\t\t\tif (pluginsProp && j.ArrayExpression.check(pluginsProp.value)) {\n\t\t\t\t// Prepend to existing plugins array\n\t\t\t\t(pluginsProp.value as ArrayExpressionNode).elements.unshift(pluginCall);\n\t\t\t} else {\n\t\t\t\t// Create new plugins property at the start\n\t\t\t\tconfig.properties.unshift(\n\t\t\t\t\tj.objectProperty(\n\t\t\t\t\t\tj.identifier(\"plugins\"),\n\t\t\t\t\t\tj.arrayExpression([pluginCall])\n\t\t\t\t\t)\n\t\t\t\t);\n\t\t\t}\n\n\t\t\t// Remove poolOptions from test\n\t\t\ttestObj.properties = testObj.properties.filter(\n\t\t\t\t(prop) => !isNamedProp(j, prop, \"poolOptions\")\n\t\t\t);\n\t\t});\n\n\treturn root.toSource();\n}\n\n// Tell jscodeshift to use the TypeScript parser\nexport const parser = \"ts\";\n"],"mappings":";AA0HA,SAAS,YACR,GACA,MACA,MACuB;AACvB,SACE,EAAE,SAAS,MAAM,KAAK,IAAI,EAAE,eAAe,MAAM,KAAK,KACvD,EAAE,WAAW,MAAM,KAAK,IAAI,IAC3B,KAAK,IAAuB,SAAS;;AAIxC,S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kBAAkB,cACvB,GACA,QAAQ,YACR,cACA;AACD,MACC,CAAC,mBACD,CAAC,EAAE,iBAAiB,MAAM,gBAAgB,MAAM,CAEhD,OAAM,IAAI,MAAM,uDAAuD;EAExE,MAAM,iBAAiB,gBAAgB;EAEvC,MAAM,cAAc,cACnB,GACA,eAAe,YACf,UACA;AACD,MACC,CAAC,eACD,EACC,EAAE,iBAAiB,MAAM,YAAY,MAAM,IAC3C,EAAE,mBAAmB,MAAM,YAAY,MAAM,IAC7C,EAAE,wBAAwB,MAAM,YAAY,MAAM,EAGnD,OAAM,IAAI,MACT,+DACA;EAIF,MAAM,aAAa,EAAE,eAAe,EAAE,WAAW,iBAAiB,EAAE,CACnE,YAAY,MACZ,CAAC;EAEF,MAAM,cAAc,cAAc,GAAG,OAAO,YAAY,UAAU;AAClE,MAAI,eAAe,EAAE,gBAAgB,MAAM,YAAY,MAAM,CAE5D,CAAC,YAAY,MAA8B,SAAS,QAAQ,WAAW;MAGvE,QAAO,WAAW,QACjB,EAAE,eACD,EAAE,WAAW,UAAU,EACvB,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAC/B,CACD;AAIF,UAAQ,aAAa,QAAQ,WAAW,QACtC,SAAS,CAAC,YAAY,GAAG,MAAM,cAAc,CAC9C;GACA;AAEH,QAAO,KAAK,UAAU;;AAIvB,MAAa,SAAS"}
|
package/dist/pool/index.mjs
CHANGED
|
@@ -8083,7 +8083,7 @@ var validateStreamingTailConsumers = /* @__PURE__ */ __name((diagnostics, field,
|
|
|
8083
8083
|
}, "validateStreamingTailConsumers");
|
|
8084
8084
|
function normalizeAndValidateEnvironment(diagnostics, configPath, rawEnv, isDispatchNamespace, preserveOriginalMain, envName = "top level", topLevelEnv, useServiceEnvironments, rawConfig) {
|
|
8085
8085
|
deprecated(diagnostics, rawEnv, "node_compat", `The "node_compat" field is no longer supported as of Wrangler v4. Instead, use the \`nodejs_compat\` compatibility flag. This includes the functionality from legacy \`node_compat\` polyfills and natively implemented Node.js APIs. See https://developers.cloudflare.com/workers/runtime-apis/nodejs for more information.`, true, "Removed", "error");
|
|
8086
|
-
experimental(diagnostics, rawEnv, "unsafe");
|
|
8086
|
+
if (topLevelEnv === void 0 || rawConfig?.unsafe === void 0) experimental(diagnostics, rawEnv, "unsafe");
|
|
8087
8087
|
const route = normalizeAndValidateRoute(diagnostics, topLevelEnv, rawEnv);
|
|
8088
8088
|
const account_id = inheritableInWranglerEnvironments(diagnostics, useServiceEnvironments, topLevelEnv, mutateEmptyStringAccountIDValue(diagnostics, rawEnv), "account_id", isString, void 0, void 0);
|
|
8089
8089
|
const routes = validateRoutes(diagnostics, topLevelEnv, rawEnv);
|
|
@@ -8246,9 +8246,11 @@ var validateDefines = /* @__PURE__ */ __name((envName) => (diagnostics, field, v
|
|
|
8246
8246
|
if (configDefines.length > 0) {
|
|
8247
8247
|
if (typeof value === "object" && value !== null) {
|
|
8248
8248
|
const configEnvDefines = config === void 0 ? [] : Object.keys(value);
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
|
|
8249
|
+
const missingDefines = configDefines.filter((varName) => !(varName in value));
|
|
8250
|
+
if (missingDefines.length > 0) diagnostics.warnings.push(`The following define entries exist at the top level, but not on "${fieldPath}".
|
|
8251
|
+
This is probably not what you want, since "define" configuration is not inherited by environments.
|
|
8252
|
+
Please add these entries to "env.${envName}.define":
|
|
8253
|
+
` + missingDefines.map((varName) => `- ${varName}`).join("\n"));
|
|
8252
8254
|
for (const varName of configEnvDefines) if (!configDefines.includes(varName)) diagnostics.warnings.push(`"${varName}" exists on "env.${envName}", but not on the top level.
|
|
8253
8255
|
This is not what you probably want, since "define" configuration within environments can only override existing top level "define" configuration
|
|
8254
8256
|
Please remove "${fieldPath}.${varName}", or add "define.${varName}".`);
|
|
@@ -8272,9 +8274,11 @@ var validateVars = /* @__PURE__ */ __name((envName) => (diagnostics, field, valu
|
|
|
8272
8274
|
const configVars = Object.keys(config?.vars ?? {});
|
|
8273
8275
|
if (configVars.length > 0) {
|
|
8274
8276
|
if (typeof value === "object" && value !== null) {
|
|
8275
|
-
|
|
8276
|
-
|
|
8277
|
-
|
|
8277
|
+
const missingVars = configVars.filter((varName) => !(varName in value));
|
|
8278
|
+
if (missingVars.length > 0) diagnostics.warnings.push(`The following vars exist at the top level, but not on "${fieldPath}".
|
|
8279
|
+
This is probably not what you want, since "vars" configuration is not inherited by environments.
|
|
8280
|
+
Please add these vars to "env.${envName}.vars":
|
|
8281
|
+
` + missingVars.map((varName) => `- ${varName}`).join("\n"));
|
|
8278
8282
|
}
|
|
8279
8283
|
}
|
|
8280
8284
|
return isValid2;
|
|
@@ -10295,27 +10299,36 @@ function startTunnel(options) {
|
|
|
10295
10299
|
const timeoutMs = options.timeoutMs ?? TUNNEL_STARTUP_TIMEOUT_MS;
|
|
10296
10300
|
const reminderIntervalMs = options.reminderIntervalMs ?? DEFAULT_TUNNEL_REMINDER_INTERVAL_MS;
|
|
10297
10301
|
const defaultExpiryMs = options.expiryMs ?? DEFAULT_TUNNEL_EXPIRY_MS;
|
|
10302
|
+
const isNamedTunnel = options.token !== void 0;
|
|
10298
10303
|
const timeFormatter = new Intl.DateTimeFormat(void 0, { timeStyle: "short" });
|
|
10299
|
-
const readyPromise = spawnCloudflared([
|
|
10304
|
+
const readyPromise = spawnCloudflared(isNamedTunnel ? [
|
|
10305
|
+
"tunnel",
|
|
10306
|
+
"--no-autoupdate",
|
|
10307
|
+
"run"
|
|
10308
|
+
] : [
|
|
10300
10309
|
"tunnel",
|
|
10301
10310
|
"--no-autoupdate",
|
|
10302
10311
|
"--url",
|
|
10303
10312
|
options.origin.href
|
|
10304
10313
|
], {
|
|
10305
10314
|
stdio: "pipe",
|
|
10315
|
+
env: options.token ? { TUNNEL_TOKEN: options.token } : void 0,
|
|
10306
10316
|
skipVersionCheck: true,
|
|
10307
10317
|
logger
|
|
10308
10318
|
}).then((process2) => {
|
|
10309
10319
|
cloudflaredProcess = process2;
|
|
10310
10320
|
if (disposed) terminateCloudflared(process2);
|
|
10311
10321
|
return process2;
|
|
10312
|
-
}).then((process2) =>
|
|
10313
|
-
|
|
10314
|
-
|
|
10315
|
-
|
|
10322
|
+
}).then((process2) => {
|
|
10323
|
+
if (isNamedTunnel) return { mode: "named" };
|
|
10324
|
+
return waitForQuickTunnelReady(process2, timeoutMs, {
|
|
10325
|
+
logger,
|
|
10326
|
+
origin: options.origin
|
|
10327
|
+
});
|
|
10328
|
+
}).then((result) => {
|
|
10316
10329
|
expiresAt = Date.now() + defaultExpiryMs;
|
|
10317
10330
|
scheduleExpiryTimeout();
|
|
10318
|
-
scheduleReminder(result.publicUrl.origin);
|
|
10331
|
+
scheduleReminder(result.mode === "quick" ? result.publicUrl.origin : void 0);
|
|
10319
10332
|
return result;
|
|
10320
10333
|
});
|
|
10321
10334
|
function disposeTunnel() {
|
|
@@ -10341,7 +10354,7 @@ function startTunnel(options) {
|
|
|
10341
10354
|
if (disposed) return;
|
|
10342
10355
|
const remainingMs = expiresAt - Date.now();
|
|
10343
10356
|
if (remainingMs <= 0) return;
|
|
10344
|
-
logger?.log(`The tunnel is still open at ${publicURL}. It expires in ${formatTunnelDuration(remainingMs)}. ${options.extendHint ?? ""}`);
|
|
10357
|
+
logger?.log(`${publicURL ? `The tunnel is still open at ${publicURL}.` : "The tunnel is still open."} It expires in ${formatTunnelDuration(remainingMs)}. ${options.extendHint ?? ""}`);
|
|
10345
10358
|
}, reminderIntervalMs);
|
|
10346
10359
|
reminderInterval.unref?.();
|
|
10347
10360
|
}
|
|
@@ -10375,6 +10388,7 @@ function startTunnel(options) {
|
|
|
10375
10388
|
__name(extendExpiry, "extendExpiry");
|
|
10376
10389
|
return {
|
|
10377
10390
|
ready: /* @__PURE__ */ __name(() => readyPromise, "ready"),
|
|
10391
|
+
isOpen: /* @__PURE__ */ __name(() => !disposed, "isOpen"),
|
|
10378
10392
|
dispose: disposeTunnel,
|
|
10379
10393
|
extendExpiry
|
|
10380
10394
|
};
|
|
@@ -10420,7 +10434,10 @@ function waitForQuickTunnelReady(cloudflared, timeoutMs, options) {
|
|
|
10420
10434
|
if (match && !resolved) {
|
|
10421
10435
|
resolved = true;
|
|
10422
10436
|
clearTimeout(timeoutId);
|
|
10423
|
-
resolve$2({
|
|
10437
|
+
resolve$2({
|
|
10438
|
+
mode: "quick",
|
|
10439
|
+
publicUrl: new URL(match[0])
|
|
10440
|
+
});
|
|
10424
10441
|
}
|
|
10425
10442
|
});
|
|
10426
10443
|
cloudflared.on("error", (error) => {
|