-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
…importmap is not being used
- Loading branch information
There are no files selected for viewing
This file was deleted.
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 |
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]); | ||
Check failure on line 17 in packages/theme-check-common/src/checks/no-import-map/index.spec.ts GitHub Actions / Tests / OS ubuntu-latest / NodeJS 18packages/theme-check-common/src/checks/no-import-map/index.spec.ts > Module: NoImportmap > should report offense when using <script type="importmap">
Check failure on line 17 in packages/theme-check-common/src/checks/no-import-map/index.spec.ts GitHub Actions / Tests / OS ubuntu-latest / NodeJS 20packages/theme-check-common/src/checks/no-import-map/index.spec.ts > Module: NoImportmap > should report offense when using <script type="importmap">
|
||
|
||
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"); | ||
}); | ||
}); |
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), | ||
}, | ||
], | ||
}); | ||
}, | ||
}; | ||
}, | ||
}; |
This file was deleted.
This file was deleted.