@astrojs/cloudflare 7.5.3 → 7.5.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/entrypoints/server.advanced.d.ts +1 -1
- package/dist/entrypoints/server.advanced.js +39 -43
- package/dist/entrypoints/server.directory.d.ts +1 -1
- package/dist/entrypoints/server.directory.js +41 -45
- package/dist/getAdapter.js +26 -32
- package/dist/index.js +476 -423
- package/dist/util.js +12 -17
- package/dist/utils/deduplicatePatterns.js +22 -14
- package/dist/utils/getCFObject.js +64 -65
- package/dist/utils/parser.js +129 -124
- package/dist/utils/prependForwardSlash.js +2 -5
- package/dist/utils/rewriteWasmImportPath.js +22 -24
- package/dist/utils/wasm-module-loader.js +92 -79
- package/package.json +15 -16
- package/LICENSE +0 -61
|
@@ -1,88 +1,101 @@
|
|
|
1
|
-
import * as fs from
|
|
2
|
-
import * as path from
|
|
3
|
-
import {} from
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
)
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
1
|
+
import * as fs from 'node:fs';
|
|
2
|
+
import * as path from 'node:path';
|
|
3
|
+
import {} from 'vite';
|
|
4
|
+
/**
|
|
5
|
+
* Loads '*.wasm?module' imports as WebAssembly modules, which is the only way to load WASM in cloudflare workers.
|
|
6
|
+
* Current proposal for WASM modules: https://github.com/WebAssembly/esm-integration/tree/main/proposals/esm-integration
|
|
7
|
+
* Cloudflare worker WASM from javascript support: https://developers.cloudflare.com/workers/runtime-apis/webassembly/javascript/
|
|
8
|
+
* @param disabled - if true throws a helpful error message if wasm is encountered and wasm imports are not enabled,
|
|
9
|
+
* otherwise it will error obscurely in the esbuild and vite builds
|
|
10
|
+
* @param assetsDirectory - the folder name for the assets directory in the build directory. Usually '_astro'
|
|
11
|
+
* @returns Vite plugin to load WASM tagged with '?module' as a WASM modules
|
|
12
|
+
*/
|
|
13
|
+
export function wasmModuleLoader({ disabled, assetsDirectory, }) {
|
|
14
|
+
const postfix = '.wasm?module';
|
|
15
|
+
let isDev = false;
|
|
16
|
+
return {
|
|
17
|
+
name: 'vite:wasm-module-loader',
|
|
18
|
+
enforce: 'pre',
|
|
19
|
+
configResolved(config) {
|
|
20
|
+
isDev = config.command === 'serve';
|
|
21
|
+
},
|
|
22
|
+
config(_, __) {
|
|
23
|
+
// let vite know that file format and the magic import string is intentional, and will be handled in this plugin
|
|
24
|
+
return {
|
|
25
|
+
assetsInclude: ['**/*.wasm?module'],
|
|
26
|
+
build: { rollupOptions: { external: /^__WASM_ASSET__.+\.wasm\.mjs$/i } },
|
|
27
|
+
};
|
|
28
|
+
},
|
|
29
|
+
load(id, _) {
|
|
30
|
+
if (!id.endsWith(postfix)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
if (disabled) {
|
|
34
|
+
throw new Error(`WASM module's cannot be loaded unless you add \`wasmModuleImports: true\` to your astro config.`);
|
|
35
|
+
}
|
|
36
|
+
const filePath = id.slice(0, -1 * '?module'.length);
|
|
37
|
+
const data = fs.readFileSync(filePath);
|
|
38
|
+
const base64 = data.toString('base64');
|
|
39
|
+
const base64Module = `
|
|
35
40
|
const wasmModule = new WebAssembly.Module(Uint8Array.from(atob("${base64}"), c => c.charCodeAt(0)));
|
|
36
41
|
export default wasmModule
|
|
37
42
|
`;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
43
|
+
if (isDev) {
|
|
44
|
+
// no need to wire up the assets in dev mode, just rewrite
|
|
45
|
+
return base64Module;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// just some shared ID
|
|
49
|
+
let hash = hashString(base64);
|
|
50
|
+
// emit the wasm binary as an asset file, to be picked up later by the esbuild bundle for the worker.
|
|
51
|
+
// give it a shared deterministic name to make things easy for esbuild to switch on later
|
|
52
|
+
const assetName = path.basename(filePath).split('.')[0] + '.' + hash + '.wasm';
|
|
53
|
+
this.emitFile({
|
|
54
|
+
type: 'asset',
|
|
55
|
+
// put it explicitly in the _astro assets directory with `fileName` rather than `name` so that
|
|
56
|
+
// vite doesn't give it a random id in its name. We need to be able to easily rewrite from
|
|
57
|
+
// the .mjs loader and the actual wasm asset later in the ESbuild for the worker
|
|
58
|
+
fileName: path.join(assetsDirectory, assetName),
|
|
59
|
+
source: fs.readFileSync(filePath),
|
|
60
|
+
});
|
|
61
|
+
// however, by default, the SSG generator cannot import the .wasm as a module, so embed as a base64 string
|
|
62
|
+
const chunkId = this.emitFile({
|
|
63
|
+
type: 'prebuilt-chunk',
|
|
64
|
+
fileName: assetName + '.mjs',
|
|
65
|
+
code: base64Module,
|
|
66
|
+
});
|
|
67
|
+
return `
|
|
57
68
|
import wasmModule from "__WASM_ASSET__${chunkId}.wasm.mjs";
|
|
58
69
|
export default wasmModule;
|
|
59
70
|
`;
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
// output original wasm file relative to the chunk
|
|
74
|
+
renderChunk(code, chunk, _) {
|
|
75
|
+
if (isDev)
|
|
76
|
+
return;
|
|
77
|
+
if (!/__WASM_ASSET__/g.test(code))
|
|
78
|
+
return;
|
|
79
|
+
const final = code.replaceAll(/__WASM_ASSET__([a-z\d]+).wasm.mjs/g, (s, assetId) => {
|
|
80
|
+
const fileName = this.getFileName(assetId);
|
|
81
|
+
const relativePath = path
|
|
82
|
+
.relative(path.dirname(chunk.fileName), fileName)
|
|
83
|
+
.replaceAll('\\', '/'); // fix windows paths for import
|
|
84
|
+
return `./${relativePath}`;
|
|
85
|
+
});
|
|
86
|
+
return { code: final };
|
|
87
|
+
},
|
|
88
|
+
};
|
|
76
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* Returns a deterministic 32 bit hash code from a string
|
|
92
|
+
*/
|
|
77
93
|
function hashString(str) {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
94
|
+
let hash = 0;
|
|
95
|
+
for (let i = 0; i < str.length; i++) {
|
|
96
|
+
const char = str.charCodeAt(i);
|
|
97
|
+
hash = (hash << 5) - hash + char;
|
|
98
|
+
hash &= hash; // Convert to 32bit integer
|
|
99
|
+
}
|
|
100
|
+
return new Uint32Array([hash])[0].toString(36);
|
|
85
101
|
}
|
|
86
|
-
export {
|
|
87
|
-
wasmModuleLoader
|
|
88
|
-
};
|
package/package.json
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
{
|
|
2
|
+
"//comment": "test changeset-bot",
|
|
2
3
|
"name": "@astrojs/cloudflare",
|
|
3
4
|
"description": "Deploy your site to Cloudflare Workers/Pages",
|
|
4
|
-
"version": "7.5.
|
|
5
|
+
"version": "7.5.4",
|
|
5
6
|
"type": "module",
|
|
6
7
|
"types": "./dist/index.d.ts",
|
|
7
8
|
"author": "withastro",
|
|
8
9
|
"license": "MIT",
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
11
|
-
"url": "https://github.com/withastro/
|
|
12
|
-
"directory": "packages/
|
|
12
|
+
"url": "https://github.com/withastro/adapters.git",
|
|
13
|
+
"directory": "packages/cloudflare"
|
|
13
14
|
},
|
|
14
15
|
"keywords": [
|
|
15
16
|
"withastro",
|
|
16
17
|
"astro-adapter"
|
|
17
18
|
],
|
|
18
|
-
"bugs": "https://github.com/withastro/
|
|
19
|
+
"bugs": "https://github.com/withastro/adapters/issues",
|
|
19
20
|
"homepage": "https://docs.astro.build/en/guides/integrations-guide/cloudflare/",
|
|
20
21
|
"exports": {
|
|
21
22
|
".": "./dist/index.js",
|
|
@@ -27,38 +28,36 @@
|
|
|
27
28
|
"dist"
|
|
28
29
|
],
|
|
29
30
|
"dependencies": {
|
|
31
|
+
"@astrojs/underscore-redirects": "^0.3.0",
|
|
30
32
|
"@cloudflare/workers-types": "^4.20230821.0",
|
|
31
|
-
"miniflare": "
|
|
33
|
+
"miniflare": "3.20231010.0",
|
|
32
34
|
"@iarna/toml": "^2.2.5",
|
|
33
|
-
"@miniflare/cache": "^2.14.1",
|
|
34
|
-
"@miniflare/shared": "^2.14.1",
|
|
35
|
-
"@miniflare/storage-memory": "^2.14.1",
|
|
36
35
|
"dotenv": "^16.3.1",
|
|
37
36
|
"esbuild": "^0.19.2",
|
|
38
37
|
"find-up": "^6.3.0",
|
|
39
38
|
"tiny-glob": "^0.2.9",
|
|
40
|
-
"vite": "^4.4.9"
|
|
41
|
-
"@astrojs/underscore-redirects": "0.3.1"
|
|
39
|
+
"vite": "^4.4.9"
|
|
42
40
|
},
|
|
43
41
|
"peerDependencies": {
|
|
44
42
|
"astro": "^3.3.0"
|
|
45
43
|
},
|
|
46
44
|
"devDependencies": {
|
|
45
|
+
"execa": "^8.0.1",
|
|
46
|
+
"fast-glob": "^3.3.1",
|
|
47
47
|
"@types/iarna__toml": "^2.0.2",
|
|
48
|
+
"strip-ansi": "^7.1.0",
|
|
49
|
+
"astro": "^3.2.3",
|
|
48
50
|
"chai": "^4.3.7",
|
|
49
51
|
"cheerio": "1.0.0-rc.12",
|
|
50
52
|
"mocha": "^10.2.0",
|
|
51
|
-
"wrangler": "^3.
|
|
52
|
-
"
|
|
53
|
-
"astro-scripts": "0.0.14"
|
|
53
|
+
"wrangler": "^3.11.0",
|
|
54
|
+
"@astrojs/test-utils": "0.0.1"
|
|
54
55
|
},
|
|
55
56
|
"publishConfig": {
|
|
56
57
|
"provenance": true
|
|
57
58
|
},
|
|
58
59
|
"scripts": {
|
|
59
|
-
"build": "
|
|
60
|
-
"build:ci": "astro-scripts build \"src/**/*.ts\"",
|
|
61
|
-
"dev": "astro-scripts dev \"src/**/*.ts\"",
|
|
60
|
+
"build": "tsc",
|
|
62
61
|
"test": "mocha --exit --timeout 30000 test/",
|
|
63
62
|
"test:match": "mocha --exit --timeout 30000 -g"
|
|
64
63
|
}
|
package/LICENSE
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2021 Fred K. Schott
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"""
|
|
25
|
-
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/sveltejs/kit repository:
|
|
26
|
-
|
|
27
|
-
Copyright (c) 2020 [these people](https://github.com/sveltejs/kit/graphs/contributors)
|
|
28
|
-
|
|
29
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
30
|
-
|
|
31
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
32
|
-
|
|
33
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
34
|
-
"""
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
"""
|
|
38
|
-
This license applies to parts of the `packages/create-astro` and `packages/astro` subdirectories originating from the https://github.com/vitejs/vite repository:
|
|
39
|
-
|
|
40
|
-
MIT License
|
|
41
|
-
|
|
42
|
-
Copyright (c) 2019-present, Yuxi (Evan) You and Vite contributors
|
|
43
|
-
|
|
44
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
45
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
46
|
-
in the Software without restriction, including without limitation the rights
|
|
47
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
48
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
49
|
-
furnished to do so, subject to the following conditions:
|
|
50
|
-
|
|
51
|
-
The above copyright notice and this permission notice shall be included in all
|
|
52
|
-
copies or substantial portions of the Software.
|
|
53
|
-
|
|
54
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
55
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
56
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
57
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
58
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
59
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
60
|
-
SOFTWARE.
|
|
61
|
-
"""
|