Skip to content

Commit a488b9f

Browse files
authored
Merge pull request #6183 from Shopify/07-30-use_uid_for_the_assets_folder_always
Use UID for the assets folder and manifest
2 parents 000a486 + 8d49cb1 commit a488b9f

File tree

5 files changed

+27
-30
lines changed

5 files changed

+27
-30
lines changed

packages/app/src/cli/models/app/app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ export class App<
428428
handle: module.handle,
429429
uid: module.uid,
430430
uuid: identifiers?.extensions[module.localIdentifier],
431-
assets: module.uid,
431+
assets: module.outputFolderId,
432432
target: module.contextValue,
433433
config: (config ?? {}) as JsonMapType,
434434
}

packages/app/src/cli/models/extensions/extension-instance.test.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,10 @@ describe('keepBuiltSourcemapsLocally', async () => {
129129
type: 'ui_extension',
130130
handle: 'scriptToMove',
131131
directory: outputPath,
132+
uid: 'uid1',
132133
})
133-
const someDirPath = joinPath(bundleDirectory, 'some_dir')
134-
const otherDirPath = joinPath(bundleDirectory, 'other_dir')
134+
const someDirPath = joinPath(bundleDirectory, 'uid1')
135+
const otherDirPath = joinPath(bundleDirectory, 'otherUID')
135136

136137
await mkdir(someDirPath)
137138
await writeFile(joinPath(someDirPath, 'scriptToMove.js'), 'abc')
@@ -141,7 +142,7 @@ describe('keepBuiltSourcemapsLocally', async () => {
141142
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js'), 'abc')
142143
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js.map'), 'abc map')
143144

144-
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory, 'some_dir')
145+
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory)
145146

146147
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js'))).toBe(false)
147148
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js.map'))).toBe(true)
@@ -158,9 +159,10 @@ describe('keepBuiltSourcemapsLocally', async () => {
158159
type: 'ui_extension',
159160
handle: 'scriptToMove',
160161
directory: outputPath,
162+
uid: 'uid1',
161163
})
162-
const someDirPath = joinPath(bundleDirectory, 'some_dir')
163-
const otherDirPath = joinPath(bundleDirectory, 'other_dir')
164+
const someDirPath = joinPath(bundleDirectory, 'wrongUID')
165+
const otherDirPath = joinPath(bundleDirectory, 'otherUID')
164166

165167
await mkdir(someDirPath)
166168
await writeFile(joinPath(someDirPath, 'scriptToMove.js'), 'abc')
@@ -170,7 +172,7 @@ describe('keepBuiltSourcemapsLocally', async () => {
170172
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js'), 'abc')
171173
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js.map'), 'abc map')
172174

173-
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory, 'other_dir')
175+
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory)
174176

175177
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js'))).toBe(false)
176178
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js.map'))).toBe(false)
@@ -187,9 +189,10 @@ describe('keepBuiltSourcemapsLocally', async () => {
187189
type: 'web_pixel_extension',
188190
handle: 'scriptToMove',
189191
directory: outputPath,
192+
uid: 'uid1',
190193
})
191-
const someDirPath = joinPath(bundleDirectory, 'some_dir')
192-
const otherDirPath = joinPath(bundleDirectory, 'other_dir')
194+
const someDirPath = joinPath(bundleDirectory, 'uid1')
195+
const otherDirPath = joinPath(bundleDirectory, 'otherUID')
193196

194197
await mkdir(someDirPath)
195198
await writeFile(joinPath(someDirPath, 'scriptToMove.js'), 'abc')
@@ -199,7 +202,7 @@ describe('keepBuiltSourcemapsLocally', async () => {
199202
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js'), 'abc')
200203
await writeFile(joinPath(otherDirPath, 'scriptToIgnore.js.map'), 'abc map')
201204

202-
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory, 'some_dir')
205+
await extensionInstance.keepBuiltSourcemapsLocally(bundleDirectory)
203206

204207
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js'))).toBe(false)
205208
expect(fileExistsSync(joinPath(outputPath, 'dist', 'scriptToMove.js.map'))).toBe(false)

packages/app/src/cli/models/extensions/extension-instance.ts

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,10 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
140140
return this.isFunctionExtension ? 'index.wasm' : `${this.handle}.js`
141141
}
142142

143+
get outputFolderId() {
144+
return this.uid
145+
}
146+
143147
constructor(options: {
144148
configuration: TConfiguration
145149
configurationPath: string
@@ -227,10 +231,10 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
227231
return this.specification.buildValidation(this)
228232
}
229233

230-
async keepBuiltSourcemapsLocally(bundleDirectory: string, extensionId: string): Promise<void> {
234+
async keepBuiltSourcemapsLocally(bundleDirectory: string): Promise<void> {
231235
if (!this.isSourceMapGeneratingExtension) return Promise.resolve()
232236

233-
const inputPath = joinPath(bundleDirectory, extensionId)
237+
const inputPath = joinPath(bundleDirectory, this.outputFolderId)
234238

235239
const pathsToMove = await glob(`**/${this.handle}.js.map`, {
236240
cwd: inputPath,
@@ -358,29 +362,25 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
358362
}
359363
}
360364

361-
async buildForBundle(options: ExtensionBuildOptions, bundleDirectory: string, identifiers?: Identifiers) {
362-
const extensionId = this.getOutputFolderId(identifiers?.extensions[this.localIdentifier])
363-
365+
async buildForBundle(options: ExtensionBuildOptions, bundleDirectory: string) {
364366
if (this.features.includes('bundling')) {
365367
// Modules that are going to be inclued in the bundle should be built in the bundle directory
366-
this.outputPath = this.getOutputPathForDirectory(bundleDirectory, extensionId)
368+
this.outputPath = this.getOutputPathForDirectory(bundleDirectory)
367369
}
368370

369371
await this.build(options)
370372
if (this.isThemeExtension) {
371373
await bundleThemeExtension(this, options)
372374
}
373375

374-
await this.keepBuiltSourcemapsLocally(bundleDirectory, extensionId)
376+
await this.keepBuiltSourcemapsLocally(bundleDirectory)
375377
}
376378

377-
async copyIntoBundle(options: ExtensionBuildOptions, bundleDirectory: string, identifiers?: Identifiers) {
378-
const extensionId = this.getOutputFolderId(identifiers?.extensions[this.localIdentifier])
379-
379+
async copyIntoBundle(options: ExtensionBuildOptions, bundleDirectory: string) {
380380
const defaultOutputPath = this.outputPath
381381

382382
if (this.features.includes('bundling')) {
383-
this.outputPath = this.getOutputPathForDirectory(bundleDirectory, extensionId)
383+
this.outputPath = this.getOutputPathForDirectory(bundleDirectory)
384384
}
385385

386386
const buildMode = this.buildMode(options)
@@ -399,12 +399,8 @@ export class ExtensionInstance<TConfiguration extends BaseConfigType = BaseConfi
399399
}
400400
}
401401

402-
getOutputFolderId(extensionId?: string) {
403-
return extensionId ?? this.uid ?? this.handle
404-
}
405-
406-
getOutputPathForDirectory(directory: string, extensionId?: string) {
407-
const id = this.getOutputFolderId(extensionId)
402+
getOutputPathForDirectory(directory: string) {
403+
const id = this.outputFolderId
408404
const outputFile = this.isThemeExtension ? '' : joinPath('dist', this.outputFileName)
409405
return joinPath(directory, id, outputFile)
410406
}

packages/app/src/cli/services/deploy/bundle.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,11 @@ export async function bundleAndBuildExtensions(options: BundleOptions) {
3737
await extension.copyIntoBundle(
3838
{stderr, stdout, signal, app: options.app, environment: 'production'},
3939
bundleDirectory,
40-
options.identifiers,
4140
)
4241
} else {
4342
await extension.buildForBundle(
4443
{stderr, stdout, signal, app: options.app, environment: 'production'},
4544
bundleDirectory,
46-
options.identifiers,
4745
)
4846
}
4947
},

packages/app/src/cli/services/dev/app-events/app-event-watcher.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ export class AppEventWatcher extends EventEmitter {
220220
.filter((extEvent) => extEvent.type === EventType.Deleted)
221221
.map((extEvent) => extEvent.extension)
222222
const promises = extensions.map(async (ext) => {
223-
const outputPath = joinPath(this.buildOutputPath, ext.getOutputFolderId())
223+
const outputPath = joinPath(this.buildOutputPath, ext.outputFolderId)
224224
return rmdir(outputPath, {force: true})
225225
})
226226
await Promise.all(promises)

0 commit comments

Comments
 (0)