Skip to content
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

Version info thingy #8761

Merged
merged 20 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/playground/src/App.svelte
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
<script>
import Counter from "./lib/Counter.svelte";
</script>

<div>
Hello world!
</div>
7 changes: 6 additions & 1 deletion packages/playground/start.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ function create_plugin(ssr = false) {
ssr ? '../svelte/src/runtime/ssr.js' : '../svelte/src/runtime/index.js'
);
} else if (id.startsWith('svelte/')) {
return path.resolve(__dirname, `../svelte/src/runtime/${id.slice(7)}/index.js`);
return path.resolve(
__dirname,
id === 'svelte/tag-version'
? '../svelte/src/runtime/tag-version.js'
: `../svelte/src/runtime/${id.slice(7)}/index.js`
);
}
},
transform(code, id) {
Expand Down
3 changes: 3 additions & 0 deletions packages/svelte/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
"types": "./types/index.d.ts",
"import": "./src/runtime/store/index.js"
},
"./tag-version": {
gtm-nayan marked this conversation as resolved.
Show resolved Hide resolved
"import": "./src/runtime/tag-version.js"
},
"./transition": {
"types": "./types/index.d.ts",
"import": "./src/runtime/transition/index.js"
Expand Down
3 changes: 2 additions & 1 deletion packages/svelte/src/compiler/compile/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const valid_options = [
'loopGuardTimeout',
'preserveComments',
'preserveWhitespace',
'cssHash'
'cssHash',
'disableVersionTagging'
gtm-nayan marked this conversation as resolved.
Show resolved Hide resolved
];
const valid_css_values = [true, false, 'injected', 'external', 'none'];
const regex_valid_identifier = /^[a-zA-Z_$][a-zA-Z_$0-9]*$/;
Expand Down
14 changes: 14 additions & 0 deletions packages/svelte/src/compiler/compile/render_dom/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -604,5 +604,19 @@ export default function dom(component, options) {
);
}
}

if (options.disableVersionTagging !== true) {
/** @type {import('estree').ImportDeclaration} */
const version_tag_import = {
type: 'ImportDeclaration',
specifiers: [],
source: {
type: 'Literal',
value: `${options.sveltePath ?? 'svelte'}/tag-version`
}
};
component.imports.unshift(version_tag_import);
}

return { js: flatten(body), css };
}
1 change: 1 addition & 0 deletions packages/svelte/src/compiler/interfaces.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,7 @@ export interface CompileOptions {

preserveComments?: boolean;
preserveWhitespace?: boolean;
disableVersionTagging?: boolean;
}

export interface ParserOptions {
Expand Down
5 changes: 5 additions & 0 deletions packages/svelte/src/runtime/tag-version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { VERSION } from '../shared/version.js';

if (typeof window !== 'undefined')
// @ts-ignore
(window.__svelte_versions || (window.__svelte_versions = [])).push(VERSION);
gtm-nayan marked this conversation as resolved.
Show resolved Hide resolved
5 changes: 5 additions & 0 deletions packages/svelte/test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export function create_loader(compileOptions, cwd) {
resolved = `${svelte_path}src/runtime/index.js`;
}

if (id === 'svelte/tag-version') {
return `${svelte_path}src/runtime/tag-version.js`;
}

if (id.startsWith('svelte/')) {
resolved = `${svelte_path}src/runtime/${id.slice(7)}/index.js`;
}
Expand All @@ -148,6 +152,7 @@ export function create_loader(compileOptions, cwd) {
// any imported Svelte components as well. A few edge cases aren't handled but also
// currently unused in the tests, for example `export * from`and live bindings.
let transformed = compiled.js.code
.replace(/^import ['"]([^'"]+)['"]/gm, 'await __import("$1")')
.replace(
/^import \* as (\w+) from ['"]([^'"]+)['"];?/gm,
'const $1 = await __import("$2");'
Expand Down
7 changes: 6 additions & 1 deletion packages/svelte/test/js/js-output.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ describe('js-output', () => {
let actual;

try {
const options = Object.assign({}, config.options || {});
const options = Object.assign(
{
disableVersionTagging: true
},
config.options || {}
);

actual = svelte
.compile(input, options)
Expand Down
2 changes: 2 additions & 0 deletions packages/svelte/test/runtime-browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async function run_browser_test(dir) {
__CONFIG__: path.resolve(__dirname, 'samples', dir, '_config.js'),
'assert.js': path.resolve(__dirname, 'assert.js'),
'svelte/internal': internal,
'svelte/tag-version': path.resolve('src/runtime/tag-version.js'),
svelte: index
},
plugins: [
Expand Down Expand Up @@ -171,6 +172,7 @@ async function run_custom_elements_test(dir) {
alias: {
'assert.js': path.resolve(__dirname, 'assert.js'),
'svelte/internal': internal,
'svelte/tag-version': path.resolve('src/runtime/tag-version.js'),
svelte: index
},
plugins: [
Expand Down
4 changes: 4 additions & 0 deletions packages/svelte/vitest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ export default defineConfig({
return `${__dirname}/src/runtime/index.js`;
}

if (id === 'svelte/tag-version') {
return `${__dirname}/src/runtime/tag-version.js`;
}

if (id.startsWith('svelte/')) {
return id.replace(/^svelte(.*)\/?$/, `${__dirname}/src/runtime/$1/index.js`);
}
Expand Down