-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added in a check on script tags in theme app extensions to make sure …
…importmap is not being used
- Loading branch information
1 parent
b9237f9
commit 99c2512
Showing
10 changed files
with
98 additions
and
293 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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,5 @@ | ||
--- | ||
'@shopify/theme-check-common': minor | ||
--- | ||
|
||
This theme check will check for and suggest removing script tags with type importmap on theme app extensions |
This file contains 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
31 changes: 31 additions & 0 deletions
31
packages/theme-check-common/src/checks/no-import-map/index.spec.ts
This file contains 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,31 @@ | ||
import { describe, expect, it } from 'vitest'; | ||
import { NoImportMap } from '.'; | ||
import { check as reportOffenses } from '../../test'; | ||
|
||
describe('Module: NoImportMap', () => { | ||
it('should report offense when using <script type="importmap">', async () => { | ||
const file = `<script type="importmap"> | ||
{ | ||
"imports": { | ||
"a.js": "https://foo.bar/baz.js" | ||
} | ||
} | ||
</script>`; | ||
const startIndex = file.indexOf('<script'); | ||
const endIndex = file.indexOf('</script>') + '</script>'.length; | ||
|
||
const offenses = await reportOffenses({ 'code.liquid': file }, [NoImportMap]); | ||
|
||
expect(offenses).to.have.length(1); | ||
const { message, start, end } = offenses[0]; | ||
|
||
expect(message).toEqual( | ||
'Until browsers permit multiple importmap entries, only themes can have an importmap', | ||
); | ||
expect(start.index).toEqual(startIndex); | ||
expect(end.index).toEqual(endIndex); | ||
|
||
expect(offenses[0].suggest).to.have.length(1); | ||
expect(offenses[0]!.suggest![0].message).to.equal("Remove the 'importmap' script tag"); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
packages/theme-check-common/src/checks/no-import-map/index.ts
This file contains 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,54 @@ | ||
import { ConfigTarget, LiquidCheckDefinition, Severity, SourceCodeType } from '../../types'; | ||
|
||
import { hasAttributeValueOf, isAttr, isValuedHtmlAttribute } from '../utils'; | ||
|
||
export const NoImportMap: LiquidCheckDefinition = { | ||
meta: { | ||
code: 'NoImportMap', | ||
name: 'Import map in theme app extensions', | ||
docs: { | ||
description: | ||
'Report offenses associated with import maps on script tags in theme app extensions', | ||
url: 'https://shopify.dev/docs/storefronts/themes/tools/theme-check/checks/no-import-map', | ||
}, | ||
type: SourceCodeType.LiquidHtml, | ||
severity: Severity.ERROR, | ||
schema: {}, | ||
targets: [ConfigTarget.ThemeAppExtension], | ||
}, | ||
|
||
create(context) { | ||
return { | ||
async HtmlRawNode(node) { | ||
if (node.name !== 'script') { | ||
return; | ||
} | ||
|
||
const typeImportMap = node.attributes | ||
.filter(isValuedHtmlAttribute) | ||
.some((attr) => isAttr(attr, 'type') && hasAttributeValueOf(attr, 'importmap')); | ||
|
||
const typeModule = node.attributes | ||
.filter(isValuedHtmlAttribute) | ||
.some((attr) => isAttr(attr, 'type') && hasAttributeValueOf(attr, 'importmap')); | ||
|
||
if (!typeImportMap || !typeModule) { | ||
return; | ||
} | ||
|
||
context.report({ | ||
message: | ||
'Until browsers permit multiple importmap entries, only themes can have an importmap', | ||
startIndex: node.position.start, | ||
endIndex: node.position.end, | ||
suggest: [ | ||
{ | ||
message: `Remove the 'importmap' script tag`, | ||
fix: (corrector) => corrector.remove(node.position.start, node.position.end), | ||
}, | ||
], | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
166 changes: 0 additions & 166 deletions
166
packages/theme-check-common/src/checks/valid-block-preset-settings/index.spec.ts
This file was deleted.
Oops, something went wrong.
114 changes: 0 additions & 114 deletions
114
packages/theme-check-common/src/checks/valid-block-preset-settings/index.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.