{"_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd","_rev":"5-7a6e960aca5e4d3116a111a7c5638843","name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","dist-tags":{"latest":"0.0.5"},"versions":{"0.0.0":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.0","_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.0","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"dist":{"shasum":"4c8ea014fd12715c043d73f3a9741b04aa07258a","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.0.tgz","fileCount":6,"integrity":"sha512-NE6FFpne79DIlgG8tWS1r+PCd/5Ed4Yl11+NQ03eeurMxloZgvGpb7PQ28BStsg61NZwSnwjj9Faw94fLxZ5dg==","signatures":[{"sig":"MEUCIQDtTGvz/+6togJ0rTRWba0m/wovpx0/UnOSKS/ftvlgMQIgDfDK5egbRXp0KGNhTyM6rZFTPwKYoK3Wn5yKcswfGfU=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":869532},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"97c7b51957c5d7c62b4b8071bd9c662aedf169ad","scripts":{"build":"tsup","build:watch":"tsup --watch"},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"_npmVersion":"10.2.4","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd` runtime](https://github.com/cloudflare/workerd) (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","directories":{},"_nodeVersion":"20.11.0","dependencies":{"recast":"^0.23.7","@babel/parser":"^7.24.6"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","vite":"^6.0.0-alpha.11","esbuild":"^0.15.3","typescript":"^5.0.4","@types/node":"^20.11.19","@cloudflare/workers-types":"^4.20240423.0"},"peerDependencies":{"wrangler":"^3.57.2","miniflare":"^3.20240129.3"},"_npmOperationalInternal":{"tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.0_1717172195134_0.18449019824283708","host":"s3://npm-registry-packages"}},"0.0.1":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.1","_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.1","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"dist":{"shasum":"7e844fe202da839fe580e82395b7f21400cde8e3","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.1.tgz","fileCount":6,"integrity":"sha512-X/2GQXBubZe5Us4LtsrSv+Gc94xjy8UkasqIPtVV/LBW7OTRoa4y+7/RajJUh+twejGsxXq+Gu/gfEKD8+j4NA==","signatures":[{"sig":"MEQCIBNYuRWYlDQ2K8eGwv9fIU+LM11uHUQvpOvcAv2FOLzbAiAD7JvcpwBB6GsKy+UAjNR7QZ8mL1wjDY/i6njfGjpqig==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":869726},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"97c7b51957c5d7c62b4b8071bd9c662aedf169ad","scripts":{"build":"tsup","build:watch":"tsup --watch"},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"repository":{"url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","type":"git","directory":"packages/vite-environment-provider-workerd"},"_npmVersion":"10.2.4","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd` runtime](https://github.com/cloudflare/workerd) (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","directories":{},"_nodeVersion":"20.11.0","dependencies":{"recast":"^0.23.7","@babel/parser":"^7.24.6"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","vite":"^6.0.0-alpha.11","esbuild":"^0.15.3","typescript":"^5.0.4","@types/node":"^20.11.19","@cloudflare/workers-types":"^4.20240423.0"},"peerDependencies":{"wrangler":"^3.57.2","miniflare":"^3.20240129.3"},"_npmOperationalInternal":{"tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.1_1717172433901_0.961309911196361","host":"s3://npm-registry-packages"}},"0.0.2":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.2","_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.2","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"dist":{"shasum":"c50fd7b50754982d04f5a36fc46bd98fa946619d","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.2.tgz","fileCount":6,"integrity":"sha512-EBVMlq8jbqG5UBJMXQZashPxLwCRJ2K5XQ2h/sOb2Cu2ibaPh1fyHrEiLz9vLBE5inflm1n1ltjW2q0bXM3Y8Q==","signatures":[{"sig":"MEQCIGoMBp57Pv6+DxGUIbaL3mSjI9VHJq23C07RAM3PYz7+AiBMhSponEIV/uXT90VuV8NiCnGn2k1Zs6wXf+viWuKjjg==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":874853},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"2f240704eeff851fc9ecf7252858130dd459f045","scripts":{"build":"tsup","build:watch":"tsup --watch"},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"repository":{"url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","type":"git","directory":"packages/vite-environment-provider-workerd"},"_npmVersion":"10.2.4","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","directories":{},"_nodeVersion":"20.11.0","dependencies":{"recast":"^0.23.7","@babel/parser":"^7.24.6"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","vite":"^6.0.0-alpha.11","esbuild":"^0.15.3","typescript":"^5.0.4","@types/node":"^20.11.19","@cloudflare/workers-types":"^4.20240423.0"},"peerDependencies":{"wrangler":"^3.57.2","miniflare":"^3.20240129.3"},"_npmOperationalInternal":{"tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.2_1717695796933_0.19447062426503026","host":"s3://npm-registry-packages"}},"0.0.3":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.3","_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.3","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"dist":{"shasum":"a31abdf46be73fb5af7488a9ba12910a413f7c2b","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.3.tgz","fileCount":6,"integrity":"sha512-L8QydPcBfW6pXuwFInQqzJk//uRd6ll9nhNXLvctgbVDAp1PGsDer1nJ2+7NsvyiXkT6iczHyrnjnYlv/o/Bqw==","signatures":[{"sig":"MEUCIC3kku0+IH4H3dr9THcEYy+1V5kWMBaLamaCuYQ+qWj1AiEAjPNDXHqzaeApVWapUjM0q4/CQIXKvhVccsi9zT1YAQI=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":104568},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"d1afe0be999501ecf3a7672453348f55299b32ea","scripts":{"build":"tsup","build:watch":"tsup --watch"},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"repository":{"url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","type":"git","directory":"packages/vite-environment-provider-workerd"},"_npmVersion":"10.2.4","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","directories":{},"_nodeVersion":"20.11.0","dependencies":{"recast":"^0.23.7","@babel/parser":"^7.24.6"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","vite":"^6.0.0-alpha.18","esbuild":"^0.15.3","typescript":"^5.0.4","@types/node":"^20.11.19","cjs-module-lexer":"^1.3.1","@cloudflare/workers-types":"^4.20240423.0"},"peerDependencies":{"wrangler":"^3.57.2","miniflare":"^3.20240129.3"},"_npmOperationalInternal":{"tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.3_1723804490588_0.957205900461582","host":"s3://npm-registry-packages"}},"0.0.4":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.4","_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.4","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"dist":{"shasum":"58bcbdf277f34111671e1d1ef403d597f7371703","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.4.tgz","fileCount":6,"integrity":"sha512-nEUoRNXOGyY/Z0f5lHe2KNQ4tr9ozHhZ4QNFmmcdXIRW/mVTfTiEQEWDUe5A+B/np19/B8DqwXn/Ht4xjWiinw==","signatures":[{"sig":"MEYCIQDfVhqzaExy86ZMghPijadcCWlXxX+rVxRkyQM8EkZfMAIhANs2D6igxxkytdMSXd+o8bsBYABl0rk/3hwI8Ebh3cHY","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":70577},"main":"dist/index.js","type":"module","types":"./dist/index.d.ts","gitHead":"8540014b3f0dd6295b2c91303e64320c1e31fa7d","scripts":{"build":"tsup","build:watch":"tsup --watch"},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"repository":{"url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","type":"git","directory":"packages/vite-environment-provider-workerd"},"_npmVersion":"10.2.4","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","directories":{},"_nodeVersion":"20.11.0","dependencies":{"cjs-module-lexer":"^1.3.1"},"_hasShrinkwrap":false,"devDependencies":{"tsup":"^8.0.2","typescript":"^5.1.6","@types/node":"^20.11.19","@cloudflare/workers-types":"^4.20240424.0"},"peerDependencies":{"vite":"^6.0.0-alpha.18","wrangler":"^3.57.2","miniflare":"^3.20240129.3"},"_npmOperationalInternal":{"tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.4_1723829709882_0.01308304206666766","host":"s3://npm-registry-packages"}},"0.0.5":{"name":"@dario-hacking/vite-6-alpha-environment-provider-workerd","version":"0.0.5","repository":{"type":"git","url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","directory":"packages/vite-environment-provider-workerd"},"main":"dist/index.js","type":"module","dependencies":{"cjs-module-lexer":"^1.3.1"},"devDependencies":{"@cloudflare/workers-types":"^4.20240424.0","@types/node":"^20.11.19","tsup":"^8.0.2","typescript":"^5.1.6"},"peerDependencies":{"miniflare":"^3.20240129.3","wrangler":"^3.57.2","vite":"^6.0.0-alpha.18"},"scripts":{"build":"tsup","build:watch":"tsup --watch"},"_id":"@dario-hacking/vite-6-alpha-environment-provider-workerd@0.0.5","types":"./dist/index.d.ts","description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","_integrity":"sha512-9SXOJDE4IGszLG0cRzU38OLSXyJhKkmnzoeNYPua142bvb5XCeL9zNGqXk4sjQfVd7Dhh+iut89a3ubROhkPwg==","_resolved":"/tmp/6c910ec87d0a5928e7794ede436ba9e8/dario-hacking-vite-6-alpha-environment-provider-workerd-0.0.5.tgz","_from":"file:dario-hacking-vite-6-alpha-environment-provider-workerd-0.0.5.tgz","_nodeVersion":"22.6.0","_npmVersion":"10.8.2","dist":{"integrity":"sha512-9SXOJDE4IGszLG0cRzU38OLSXyJhKkmnzoeNYPua142bvb5XCeL9zNGqXk4sjQfVd7Dhh+iut89a3ubROhkPwg==","shasum":"8789d612ccd5493baaebdcd30309ff58f90d0322","tarball":"https://registry.npmjs.org/@dario-hacking/vite-6-alpha-environment-provider-workerd/-/vite-6-alpha-environment-provider-workerd-0.0.5.tgz","fileCount":6,"unpackedSize":70580,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDqt/kmmbVqNiMUFHBEKOF0AXAiis4bg76H29HrPb5h+AIgNy7hofK0mGqq5Kq/I1n6/srcKcol07vEie9LEPyvQ+8="}]},"_npmUser":{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"},"directories":{},"maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/vite-6-alpha-environment-provider-workerd_0.0.5_1723851950777_0.13074095593888857"},"_hasShrinkwrap":false}},"time":{"created":"2024-05-31T16:16:34.999Z","modified":"2024-08-16T23:45:51.180Z","0.0.0":"2024-05-31T16:16:35.393Z","0.0.1":"2024-05-31T16:20:34.203Z","0.0.2":"2024-06-06T17:43:17.207Z","0.0.3":"2024-08-16T10:34:50.810Z","0.0.4":"2024-08-16T17:35:10.080Z","0.0.5":"2024-08-16T23:45:50.954Z"},"bugs":{"url":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations/issues"},"homepage":"https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations#readme","repository":{"type":"git","url":"git+https://github.com/dario-piotrowicz/vite-environment-6.0.0-alpha-experimentations.git","directory":"packages/vite-environment-provider-workerd"},"description":"Package that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/mai","maintainers":[{"name":"dario.piotrowicz","email":"dario.piotrowicz@gmail.com"}],"readme":"# Vite Environment Provider Workerd\n\nPackage that exports a `workerdEnvironmentProvider` function that can be used to set a Vite Environment to run code inside the [`workerd`](https://github.com/cloudflare/workerd) runtime (via [`Miniflare`](https://github.com/cloudflare/workers-sdk/tree/main/packages/miniflare)).\n\n> [!NOTE]\n> Based on the [vite@6.0.0-alpha.18](https://www.npmjs.com/package/vite/v/6.0.0-alpha.18) Environment API implementation.\n\n## Package Usage\n\nThe package exposes the `workerdEnvironmentProvider` function that can be used to create new environments that run code inside the workerd runtime:\n\n```ts\nenvironments: {\n  myEnvironment: workerdEnvironmentProvider(),\n}\n```\n\nthis sets both a `dev` and a `build` environments (of course users can also process the `workerdEnvironmentProvider` returned value to tweak the returned environments and/or use only one of them).\n\nIn the case of the dev environment, the environment instance is enhanced with an `api` field that contains a `getHandler` method, this is what can then be used to handle incoming requests (making sure that they are run inside workerd):\n\n```ts\nconst handler = await devEnv.api.getHandler({\n  entrypoint: workerEntrypoint,\n});\n```\n\nYou can see usage examples [here](../../examples/dummy-framework/frameworkPlugin.ts) and [here](https://github.com/dario-piotrowicz/remix/blob/2.9.1-vite-env-4/packages/remix-dev/vite/plugin.ts).\n\n## Package Structure\n\nThe package's code is structured in the following way:\n\n```\nsrc\n├── debug-dumps\n│   ├── ...\n│   └── ...\n├── worker\n│   └── index.ts\n├── codeTransformation.ts\n├── index.ts\n└── workerd-custom-import.cts\n```\n\n- `debug-dumps`\\\n  can be ignored, it contains logic that we've used to dump logs and files that the\n  environment encounters which we've used for debugging (this is off by default and can be enabled by setting the `DEBUG_DUMPS` env variable)\n\n- `worker/index.ts`\\\n  the actual entrypoint worker code that we run inside workerd, this includes the Vite Module Runner. It runs code by importing the `getHandler`'s `entrypoint` argument.\n\n- `codeTransformation.ts`\\\n  logic that we needed to include to make workerd correctly handles esm modules importing cjs ones, this will soon become unnecessary since changes in workerd are being worked on to fix the cjs issues\n\n- `index.ts`\\\n  the package's index file, it exposes the `workerdEnvironmentProvider` function which creates the Vite Environments. In the case of the dev one, it creates one that spins up a miniflare instance that uses the `worker/index.ts` transpiled code as is main module.\n\n- `workerd-custom-import.cts`\\\n  this is a file that we use to implement interoperability between ems and cjs (external) code.\n\n## Important points\n\n### The module fallback service\n\nIn the `index.ts` code you can see a `unsafeModuleFallbackService` this is a relatively new feature of workerd and miniflare that is instrumental here to enable the module runner's `runExternalModule` method to function in workerd.\n\nHow this works is that when workerd tries to import a module and it can't find it in its module graph then it sends a request to the module fallback service providing the import details.\n\nThe module fallback service can then fetch and return the code for the module from the filesystem (in our case using `DevEnvironment#pluginContainer#resolveId` to allow Vite to perform the correct module resolution).\n\nAllowing the import inside workerd to them be resolved (and the workerd module graph updated).\n\n### `workerd-custom-imports.cts`\n\nWorkerd supports cjs code but not as part of it's main/entrypoint module. So with a standard setup with a single esm module we wouldn't be able to import cjs modules. The way we workaround this limitation is by creating an additional `CommonJS` module which exports a custom import function (which is actually implement by a plain dynamic import) such import can then import both cjs and esm modules, allowing us to have interoperability between the two.\n","readmeFilename":"README.md"}