Add Astro.resolve deprecation warning case for script tags (#2493)
* Adding script.ts util for checking scripts files path * Adding deprecation message `Astro.resolve()` case for scripts files with suggestions
This commit is contained in:
parent
de9fadbaed
commit
95b9740431
2 changed files with 20 additions and 0 deletions
|
@ -3,6 +3,7 @@ import type { AstroConfig, AstroGlobal, AstroGlobalPartial, Params, Renderer, SS
|
|||
import { bold } from 'kleur/colors';
|
||||
import { canonicalURL as getCanonicalURL } from '../util.js';
|
||||
import { isCSSRequest } from './css.js';
|
||||
import { isScriptRequest } from './script.js';
|
||||
import { renderSlot } from '../../runtime/server/index.js';
|
||||
import { warn, LogOptions } from '../logger.js';
|
||||
|
||||
|
@ -49,6 +50,17 @@ export function createResult(args: CreateResultArgs): SSRResult {
|
|||
<style global>
|
||||
@import "${path}";
|
||||
</style>
|
||||
`;
|
||||
} else if (isScriptRequest(path)) {
|
||||
extra = `It looks like you are resolving scripts. If you are adding a script tag, replace with this:
|
||||
|
||||
<script type="module" src={(await import("${path}?url")).default}></script>
|
||||
|
||||
or consider make it a module like so:
|
||||
|
||||
<script type="module" hoist>
|
||||
import MyModule from "${path}";
|
||||
</script>
|
||||
`;
|
||||
}
|
||||
|
||||
|
|
8
packages/astro/src/core/ssr/script.ts
Normal file
8
packages/astro/src/core/ssr/script.ts
Normal file
|
@ -0,0 +1,8 @@
|
|||
export const SCRIPT_EXTENSIONS = new Set(['.js', '.ts']);
|
||||
|
||||
const scriptRe = new RegExp(
|
||||
`\\.(${Array.from(SCRIPT_EXTENSIONS)
|
||||
.map((s) => s.slice(1))
|
||||
.join('|')})($|\\?)`
|
||||
);
|
||||
export const isScriptRequest = (request: string): boolean => scriptRe.test(request);
|
Loading…
Reference in a new issue