-
Notifications
You must be signed in to change notification settings - Fork 226
Abstract build steps to externalize the build configuration #6842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alfonso-noriega
wants to merge
1
commit into
graphite-base/6842
Choose a base branch
from
02-10-abstract_build_steps_to_externalize_the_build_configuration
base: graphite-base/6842
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,620
−98
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
156 changes: 156 additions & 0 deletions
156
packages/app/src/cli/models/extensions/specifications/channel.test.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,156 @@ | ||
| import spec from './channel.js' | ||
| import {ExtensionInstance} from '../extension-instance.js' | ||
| import {ExtensionBuildOptions} from '../../../services/build/extension.js' | ||
| import {describe, expect, test} from 'vitest' | ||
| import {inTemporaryDirectory, writeFile, fileExists, mkdir} from '@shopify/cli-kit/node/fs' | ||
| import {joinPath} from '@shopify/cli-kit/node/path' | ||
| import {Writable} from 'stream' | ||
|
|
||
| const SUBDIRECTORY = 'specifications' | ||
|
|
||
| describe('channel_config', () => { | ||
| describe('buildConfig', () => { | ||
| test('uses build_steps mode', () => { | ||
| expect(spec.buildConfig.mode).toBe('copy_files') | ||
| }) | ||
|
|
||
| test('has a single copy-files step scoped to the specifications subdirectory', () => { | ||
| if (spec.buildConfig.mode === 'none') throw new Error('Expected build_steps mode') | ||
|
|
||
| expect(spec.buildConfig.steps).toHaveLength(1) | ||
| expect(spec.buildConfig.steps![0]).toMatchObject({ | ||
| id: 'copy-files', | ||
| type: 'copy_files', | ||
| config: { | ||
| strategy: 'pattern', | ||
| definition: {source: '.'}, | ||
| }, | ||
| }) | ||
|
|
||
| const {patterns} = (spec.buildConfig.steps![0]!.config as {definition: {patterns: string[]}}).definition | ||
|
|
||
| expect(patterns).toEqual( | ||
| expect.arrayContaining([ | ||
| `${SUBDIRECTORY}/**/*.json`, | ||
| `${SUBDIRECTORY}/**/*.toml`, | ||
| `${SUBDIRECTORY}/**/*.yaml`, | ||
| `${SUBDIRECTORY}/**/*.yml`, | ||
| `${SUBDIRECTORY}/**/*.svg`, | ||
| ]), | ||
| ) | ||
| }) | ||
|
|
||
| test('config is serializable to JSON', () => { | ||
| if (spec.buildConfig.mode === 'none') throw new Error('Expected build_steps mode') | ||
|
|
||
| const serialized = JSON.stringify(spec.buildConfig) | ||
| const deserialized = JSON.parse(serialized) | ||
|
|
||
| expect(deserialized.steps).toHaveLength(1) | ||
| expect(deserialized.steps[0].config.strategy).toBe('pattern') | ||
| }) | ||
| }) | ||
|
|
||
| describe('build integration', () => { | ||
| test('copies specification files to output, preserving subdirectory structure', async () => { | ||
| await inTemporaryDirectory(async (tmpDir) => { | ||
| // Given | ||
| const extensionDir = joinPath(tmpDir, 'extension') | ||
| const specsDir = joinPath(extensionDir, SUBDIRECTORY) | ||
| const outputDir = joinPath(tmpDir, 'output') | ||
|
|
||
| await mkdir(specsDir) | ||
| await mkdir(outputDir) | ||
|
|
||
| await writeFile(joinPath(specsDir, 'product.json'), '{}') | ||
| await writeFile(joinPath(specsDir, 'order.toml'), '[spec]') | ||
| await writeFile(joinPath(specsDir, 'logo.svg'), '<svg/>') | ||
| // Root-level files should NOT be copied | ||
| await writeFile(joinPath(extensionDir, 'README.md'), '# readme') | ||
| await writeFile(joinPath(extensionDir, 'index.js'), 'ignored') | ||
|
|
||
| const extension = new ExtensionInstance({ | ||
| configuration: {name: 'my-channel', type: 'channel'}, | ||
| configurationPath: '', | ||
| directory: extensionDir, | ||
| specification: spec, | ||
| }) | ||
| extension.outputPath = outputDir | ||
|
|
||
| const buildOptions: ExtensionBuildOptions = { | ||
| stdout: new Writable({ | ||
| write(chunk, enc, cb) { | ||
| cb() | ||
| }, | ||
| }), | ||
| stderr: new Writable({ | ||
| write(chunk, enc, cb) { | ||
| cb() | ||
| }, | ||
| }), | ||
| app: {} as any, | ||
| environment: 'production', | ||
| } | ||
|
|
||
| // When | ||
| await extension.build(buildOptions) | ||
|
|
||
| // Then — specification files copied with path preserved | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'product.json'))).resolves.toBe(true) | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'order.toml'))).resolves.toBe(true) | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'logo.svg'))).resolves.toBe(true) | ||
|
|
||
| // Root-level files not in specifications/ are not copied | ||
| await expect(fileExists(joinPath(outputDir, 'README.md'))).resolves.toBe(false) | ||
| await expect(fileExists(joinPath(outputDir, 'index.js'))).resolves.toBe(false) | ||
| }) | ||
| }) | ||
|
|
||
| test('does not copy files with non-matching extensions inside specifications/', async () => { | ||
| await inTemporaryDirectory(async (tmpDir) => { | ||
| // Given | ||
| const extensionDir = joinPath(tmpDir, 'extension') | ||
| const specsDir = joinPath(extensionDir, SUBDIRECTORY) | ||
| const outputDir = joinPath(tmpDir, 'output') | ||
|
|
||
| await mkdir(specsDir) | ||
| await mkdir(outputDir) | ||
|
|
||
| await writeFile(joinPath(specsDir, 'spec.json'), '{}') | ||
| await writeFile(joinPath(specsDir, 'ignored.ts'), 'const x = 1') | ||
| await writeFile(joinPath(specsDir, 'ignored.js'), 'const x = 1') | ||
|
|
||
| const extension = new ExtensionInstance({ | ||
| configuration: {name: 'my-channel', type: 'channel'}, | ||
| configurationPath: '', | ||
| directory: extensionDir, | ||
| specification: spec, | ||
| }) | ||
| extension.outputPath = outputDir | ||
|
|
||
| const buildOptions: ExtensionBuildOptions = { | ||
| stdout: new Writable({ | ||
| write(chunk, enc, cb) { | ||
| cb() | ||
| }, | ||
| }), | ||
| stderr: new Writable({ | ||
| write(chunk, enc, cb) { | ||
| cb() | ||
| }, | ||
| }), | ||
| app: {} as any, | ||
| environment: 'production', | ||
| } | ||
|
|
||
| // When | ||
| await extension.build(buildOptions) | ||
|
|
||
| // Then | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'spec.json'))).resolves.toBe(true) | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'ignored.ts'))).resolves.toBe(false) | ||
| await expect(fileExists(joinPath(outputDir, SUBDIRECTORY, 'ignored.js'))).resolves.toBe(false) | ||
| }) | ||
| }) | ||
| }) | ||
| }) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keep
modeandsteps? the mode doesn't do anything anymore with this implementation right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mode is still used in two other places of this file, so i keep it here untill the other to usages get sorted out and replaced