1- import { runCommand } from '@oclif/test'
2- import { expect } from 'chai'
3- import { execSync } from 'node:child_process'
1+ import { runCommand } from '@oclif/test'
2+ import { expect } from 'chai'
3+ import { execSync } from 'node:child_process'
44import * as fs from 'node:fs'
55import * as path from 'node:path'
6- import { fileURLToPath } from 'node:url'
6+ import { fileURLToPath } from 'node:url'
77
88const __dirname = path . dirname ( fileURLToPath ( import . meta. url ) )
99const fixturesPath = path . join ( __dirname , '../../../fixtures' )
@@ -15,34 +15,34 @@ const testCollectionBPath = path.join(fixturesPath, 'test-collection-b')
1515const testThemePath = path . join ( fixturesPath , 'test-theme' )
1616describe ( 'theme component manifest' , ( ) => {
1717 beforeEach ( ( ) => {
18- fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
19- fs . cpSync ( collectionBPath , testCollectionBPath , { recursive : true } )
20- fs . cpSync ( themePath , testThemePath , { recursive : true } )
18+ fs . cpSync ( collectionPath , testCollectionPath , { recursive : true } )
19+ fs . cpSync ( collectionBPath , testCollectionBPath , { recursive : true } )
20+ fs . cpSync ( themePath , testThemePath , { recursive : true } )
2121 process . chdir ( testCollectionPath )
2222 } )
2323
2424 afterEach ( ( ) => {
25- fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
26- fs . rmSync ( testCollectionBPath , { force : true , recursive : true } )
27- fs . rmSync ( testThemePath , { force : true , recursive : true } )
25+ fs . rmSync ( testCollectionPath , { force : true , recursive : true } )
26+ fs . rmSync ( testCollectionBPath , { force : true , recursive : true } )
27+ fs . rmSync ( testThemePath , { force : true , recursive : true } )
2828 } )
2929
3030 it ( 'should throw an error if the cwd is not a component collection' , async ( ) => {
3131 process . chdir ( testThemePath )
32- const { error} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
32+ const { error } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
3333 expect ( error ) . to . be . instanceOf ( Error )
3434 expect ( error ?. message ) . to . include ( 'Warning: ' )
3535 } )
3636
3737 it ( 'should throw an error if a theme directory is not provided' , async ( ) => {
38- const { error} = await runCommand ( [ 'theme' , 'component' , 'manifest' ] )
38+ const { error } = await runCommand ( [ 'theme' , 'component' , 'manifest' ] )
3939 expect ( error ) . to . be . instanceOf ( Error )
4040 expect ( error ?. message ) . to . include ( 'Missing 1 required arg:' )
4141 } )
4242
4343 it ( 'creates a component.manifest.json in current theme directory if it does not exist' , async ( ) => {
4444 // Confirm that the file does not exist
45- fs . rmSync ( path . join ( testThemePath , 'component.manifest.json' ) , { force : true } )
45+ fs . rmSync ( path . join ( testThemePath , 'component.manifest.json' ) , { force : true } )
4646 expect ( fs . existsSync ( path . join ( testThemePath , 'component.manifest.json' ) ) ) . to . be . false
4747
4848 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
@@ -114,28 +114,28 @@ describe('theme component manifest', () => {
114114 } )
115115
116116 it ( 'throws a warning if there is a potential conflict with an entry in the current collection' , async ( ) => {
117- const { stdout} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
117+ const { stdout } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
118118 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
119119 expect ( stdout ) . to . include ( 'Conflict Warning: Pre-existing file' )
120120 expect ( data . files . snippets [ 'conflict.liquid' ] ) . to . equal ( '@theme' )
121121 } )
122122
123123 it ( 'ignores conflicts if --ignore-conflicts flag is passed' , async ( ) => {
124- const { stdout} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , '--ignore-conflicts' ] )
124+ const { stdout } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , '--ignore-conflicts' ] )
125125 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
126126 expect ( stdout ) . to . not . include ( 'Conflict Warning: Pre-existing file' )
127127 expect ( data . files . snippets [ 'conflict.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
128128 } )
129129
130130 it ( 'throws a warning when an override is detected' , async ( ) => {
131- const { stdout} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
131+ const { stdout } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
132132 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
133133 expect ( stdout ) . to . include ( 'Override Warning:' )
134134 expect ( data . files . snippets [ 'override.liquid' ] ) . to . equal ( '@theme' )
135135 } )
136136
137137 it ( 'overriden parent still references non-overridden child from collection' , async ( ) => {
138- const { stdout} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
138+ const { stdout } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
139139 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
140140 expect ( stdout ) . to . include ( 'Override Warning:' )
141141 expect ( data . files . snippets [ 'override-parent.liquid' ] ) . to . equal ( '@theme' )
@@ -144,7 +144,7 @@ describe('theme component manifest', () => {
144144 } )
145145
146146 it ( 'ignores overrides if --ignore-overrides flag is passed' , async ( ) => {
147- const { stdout} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , '--ignore-overrides' ] )
147+ const { stdout } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , '--ignore-overrides' ] )
148148 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
149149 expect ( stdout ) . to . not . include ( 'Override Warning:' )
150150 expect ( data . files . snippets [ 'override.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
@@ -176,7 +176,7 @@ describe('theme component manifest', () => {
176176
177177 it ( 'persists entries from other collections or @theme if those files still exist' , async ( ) => {
178178 const beforeData = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
179-
179+
180180 // Check that referenced files are present in map
181181 expect ( beforeData . files . snippets [ 'theme-component.liquid' ] ) . to . equal ( '@theme' )
182182 expect ( beforeData . files . assets [ 'theme-component.css' ] ) . to . equal ( '@theme' )
@@ -230,7 +230,7 @@ describe('theme component manifest', () => {
230230 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , 'new' ] )
231231
232232 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
233-
233+
234234 // Should include the selected component and its assets
235235 expect ( data . files . snippets [ 'new.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
236236 expect ( data . files . assets [ 'new.css' ] ) . to . equal ( '@archetype-themes/test-collection' )
@@ -244,7 +244,7 @@ describe('theme component manifest', () => {
244244 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , 'new,parent' ] )
245245
246246 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
247-
247+
248248 // Should include both selected components and their dependencies
249249 expect ( data . files . snippets [ 'new.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
250250 expect ( data . files . assets [ 'new.css' ] ) . to . equal ( '@archetype-themes/test-collection' )
@@ -257,37 +257,37 @@ describe('theme component manifest', () => {
257257 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , 'child' ] )
258258
259259 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
260-
260+
261261 // Should not include the snippet since it's not a component
262262 expect ( data . files . snippets [ 'child.liquid' ] ) . to . be . undefined
263263 } )
264264
265265 it ( 'should include all components when using "*" as component selector' , async ( ) => {
266266 const beforeData = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
267-
267+
268268 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , '*' ] )
269269
270270 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
271-
271+
272272 // Should include all components from the collection
273273 expect ( data . files . snippets [ 'new.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
274274 expect ( data . files . assets [ 'new.css' ] ) . to . equal ( '@archetype-themes/test-collection' )
275275 expect ( data . files . snippets [ 'parent.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
276276 expect ( data . files . snippets [ 'child.liquid' ] ) . to . equal ( '@archetype-themes/test-collection' )
277-
277+
278278 // Should still maintain other collection entries
279279 for ( const [ key , value ] of Object . entries ( beforeData . files . snippets )
280280 . filter ( ( [ _ , value ] ) => value !== '@archetype-themes/test-collection' ) ) {
281- if ( fs . existsSync ( path . join ( testThemePath , 'snippets' , key ) ) ) {
282- expect ( data . files . snippets [ key ] ) . to . equal ( value )
283- }
281+ if ( fs . existsSync ( path . join ( testThemePath , 'snippets' , key ) ) ) {
282+ expect ( data . files . snippets [ key ] ) . to . equal ( value )
284283 }
284+ }
285285 } )
286286
287287 it ( 'should throw an error when no components match the selector' , async ( ) => {
288288 const beforeData = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
289-
290- const { error} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , 'non-existent' ] )
289+
290+ const { error } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath , 'non-existent' ] )
291291
292292 // Should throw an error
293293 expect ( error ) . to . be . instanceOf ( Error )
@@ -312,29 +312,29 @@ describe('theme component manifest', () => {
312312 it ( 'should detect JS imports from script tags with {{ "filename" | asset_url }} filter' , async ( ) => {
313313 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
314314 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
315-
315+
316316 expect ( data . files . assets [ 'script-with-filter.js' ] ) . to . equal ( '@archetype-themes/test-collection' )
317317 } )
318318
319319 it ( 'should detect JS imports snippets inside components' , async ( ) => {
320320 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
321321 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
322-
322+
323323 expect ( data . files . assets [ 'script-snippet-import.js' ] ) . to . equal ( '@archetype-themes/test-collection' )
324324 } )
325325
326326 it ( 'should detect JS imports from script tags with import statements' , async ( ) => {
327327 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
328328 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
329-
329+
330330 expect ( data . files . assets [ 'script-with-import.js' ] ) . to . equal ( '@archetype-themes/test-collection' )
331331 expect ( data . files . assets [ 'shared-min-other.js' ] ) . to . equal ( '@archetype-themes/test-collection' )
332332 } )
333333
334334 it ( 'should not include commented out script imports' , async ( ) => {
335335 await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
336336 const data = JSON . parse ( fs . readFileSync ( path . join ( testThemePath , 'component.manifest.json' ) , 'utf8' ) )
337-
337+
338338 expect ( data . files . assets [ 'commented-script.js' ] ) . to . be . undefined
339339 } )
340340
@@ -345,9 +345,9 @@ describe('theme component manifest', () => {
345345 execSync ( 'git config user.name "Test User"' , { cwd : testCollectionPath } )
346346 execSync ( 'git add .' , { cwd : testCollectionPath } )
347347 execSync ( 'git commit -m "Initial commit"' , { cwd : testCollectionPath } )
348-
348+
349349 // Get the commit hash we just created
350- const expectedHash = execSync ( 'git rev-parse HEAD' , {
350+ const expectedHash = execSync ( 'git rev-parse HEAD' , {
351351 cwd : testCollectionPath ,
352352 encoding : 'utf8'
353353 } ) . trim ( )
@@ -361,11 +361,11 @@ describe('theme component manifest', () => {
361361 it ( 'should throw an error if there are duplicate files in the source collection' , async ( ) => {
362362 const src = path . join ( testCollectionPath , 'components' , 'duplicate' , 'duplicate.liquid' )
363363 const dest = path . join ( testCollectionPath , 'components' , 'duplicate' , 'snippets' , 'duplicate.liquid' )
364-
365- fs . cpSync ( src , dest , { recursive : true } )
366364
367- const { error} = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
365+ fs . cpSync ( src , dest , { recursive : true } )
366+
367+ const { error } = await runCommand ( [ 'theme' , 'component' , 'manifest' , testThemePath ] )
368368 expect ( error ) . to . be . instanceOf ( Error )
369- expect ( error ?. message ) . to . include ( 'Error: Namespace conflict in source component collection with ' )
369+ expect ( error ?. message ) . to . include ( 'Warning: Found duplicate files for ' )
370370 } )
371371} )
0 commit comments