@@ -9,8 +9,9 @@ import { DenoBridge } from '../bridge.js'
9
9
import { Bundle , BundleFormat } from '../bundle.js'
10
10
import { EdgeFunction } from '../edge_function.js'
11
11
import { FeatureFlags } from '../feature_flags.js'
12
+ import { listRecursively } from '../utils/fs.js'
12
13
import { ImportMap } from '../import_map.js'
13
- import { getDirectoryHash , getStringHash } from '../utils/sha256.js'
14
+ import { getFileHash } from '../utils/sha256.js'
14
15
15
16
const TARBALL_EXTENSION = '.tar'
16
17
@@ -42,8 +43,8 @@ export const bundle = async ({
42
43
importMap,
43
44
vendorDirectory,
44
45
} : BundleTarballOptions ) : Promise < Bundle > => {
45
- const sideFilesDir = await tmp . dir ( { unsafeCleanup : true } )
46
- const cleanup = [ sideFilesDir . cleanup ]
46
+ const bundleDir = await tmp . dir ( { unsafeCleanup : true } )
47
+ const cleanup = [ bundleDir . cleanup ]
47
48
48
49
let denoDir = vendorDirectory ? path . join ( vendorDirectory , 'deno_dir' ) : undefined
49
50
@@ -87,71 +88,47 @@ export const bundle = async ({
87
88
'--quiet' ,
88
89
'--code-splitting' ,
89
90
'--outdir' ,
90
- distDirectory ,
91
+ bundleDir . path ,
91
92
...functions . map ( ( func ) => func . path ) ,
92
93
] ,
93
94
{
94
95
cwd : basePath ,
95
96
} ,
96
97
)
97
98
98
- const manifestPath = path . join ( sideFilesDir . path , 'manifest .json' )
99
+ const manifestPath = path . join ( bundleDir . path , '___netlify-edge-functions .json' )
99
100
const manifestContents = JSON . stringify ( manifest )
100
101
await fs . writeFile ( manifestPath , manifestContents )
101
102
102
- const denoConfigPath = path . join ( sideFilesDir . path , 'deno.json' )
103
+ const denoConfigPath = path . join ( bundleDir . path , 'deno.json' )
103
104
const denoConfigContents = JSON . stringify ( importMap . getContentsWithRelativePaths ( ) )
104
105
await fs . writeFile ( denoConfigPath , denoConfigContents )
105
106
106
- const rootLevel = await fs . readdir ( distDirectory )
107
- const hash = await getDirectoryHash ( distDirectory )
108
107
const tarballPath = path . join ( distDirectory , buildID + TARBALL_EXTENSION )
109
-
110
108
await fs . mkdir ( path . dirname ( tarballPath ) , { recursive : true } )
111
109
112
- // Adding all the bundled files.
113
110
await tar . create (
114
111
{
115
- cwd : distDirectory ,
116
- file : tarballPath ,
117
- onWriteEntry ( entry ) {
118
- entry . path = getUnixPath ( `./${ entry . path } ` )
119
- } ,
120
- } ,
121
- rootLevel ,
122
- )
123
-
124
- // Adding `deno.json`.
125
- await tar . update (
126
- {
127
- cwd : distDirectory ,
112
+ cwd : bundleDir . path ,
128
113
file : tarballPath ,
114
+ noDirRecurse : true ,
129
115
onWriteEntry ( entry ) {
130
- entry . path = './deno.json'
131
- } ,
132
- } ,
133
- [ denoConfigPath ] ,
134
- )
116
+ const relativePath = path . relative ( bundleDir . path , path . join ( '/' , entry . path ) )
117
+ const normalizedPath = getUnixPath ( relativePath )
135
118
136
- // Adding the manifest file.
137
- await tar . update (
138
- {
139
- cwd : distDirectory ,
140
- file : tarballPath ,
141
- onWriteEntry ( entry ) {
142
- entry . path = './___netlify-edge-functions.json'
119
+ entry . path = normalizedPath
143
120
} ,
144
121
} ,
145
- [ manifestPath ] ,
122
+ await listRecursively ( bundleDir . path ) ,
146
123
)
147
124
148
- await Promise . all ( cleanup )
125
+ const hash = await getFileHash ( tarballPath )
149
126
150
- const finalHash = [ hash , getStringHash ( manifestContents ) , getStringHash ( denoConfigContents ) ] . join ( '' )
127
+ await Promise . allSettled ( cleanup )
151
128
152
129
return {
153
130
extension : TARBALL_EXTENSION ,
154
131
format : BundleFormat . TARBALL ,
155
- hash : finalHash ,
132
+ hash,
156
133
}
157
134
}
0 commit comments