mirror of
https://github.com/kevin-DL/sapper.git
synced 2026-01-21 06:45:00 +00:00
Fix filename escaping issues
This commit is contained in:
@@ -4,6 +4,7 @@ import hash from 'string-hash';
|
|||||||
import * as codec from 'sourcemap-codec';
|
import * as codec from 'sourcemap-codec';
|
||||||
import { PageComponent, Dirs } from '../../interfaces';
|
import { PageComponent, Dirs } from '../../interfaces';
|
||||||
import { CompileResult } from './interfaces';
|
import { CompileResult } from './interfaces';
|
||||||
|
import { posixify } from '../utils'
|
||||||
|
|
||||||
const inline_sourcemap_header = 'data:application/json;charset=utf-8;base64,';
|
const inline_sourcemap_header = 'data:application/json;charset=utf-8;base64,';
|
||||||
|
|
||||||
@@ -75,7 +76,7 @@ export default function extract_css(client_result: CompileResult, components: Pa
|
|||||||
const component_owners = new Map();
|
const component_owners = new Map();
|
||||||
client_result.chunks.forEach(chunk => {
|
client_result.chunks.forEach(chunk => {
|
||||||
chunk.modules.forEach(module => {
|
chunk.modules.forEach(module => {
|
||||||
const component = path.relative(dirs.routes, module);
|
const component = posixify(path.relative(dirs.routes, module));
|
||||||
component_owners.set(component, chunk);
|
component_owners.set(component, chunk);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import glob from 'tiny-glob/sync.js';
|
import glob from 'tiny-glob/sync.js';
|
||||||
import { posixify, write_if_changed } from './utils';
|
import { posixify, stringify, write_if_changed } from './utils';
|
||||||
import { dev, locations } from '../config';
|
import { dev, locations } from '../config';
|
||||||
import { Page, PageComponent, ServerRoute, ManifestData } from '../interfaces';
|
import { Page, PageComponent, ServerRoute, ManifestData } from '../interfaces';
|
||||||
|
|
||||||
@@ -36,9 +36,9 @@ export function create_serviceworker_manifest({ manifest_data, client_files }: {
|
|||||||
// This file is generated by Sapper — do not edit it!
|
// This file is generated by Sapper — do not edit it!
|
||||||
export const timestamp = ${Date.now()};
|
export const timestamp = ${Date.now()};
|
||||||
|
|
||||||
export const assets = [\n\t${assets.map((x: string) => `"${x}"`).join(',\n\t')}\n];
|
export const assets = [\n\t${assets.map((x: string) => stringify(x)).join(',\n\t')}\n];
|
||||||
|
|
||||||
export const shell = [\n\t${client_files.map((x: string) => `"${x}"`).join(',\n\t')}\n];
|
export const shell = [\n\t${client_files.map((x: string) => stringify(x)).join(',\n\t')}\n];
|
||||||
|
|
||||||
export const routes = [\n\t${manifest_data.pages.map((r: Page) => `{ pattern: ${r.pattern} }`).join(',\n\t')}\n];
|
export const routes = [\n\t${manifest_data.pages.map((r: Page) => `{ pattern: ${r.pattern} }`).join(',\n\t')}\n];
|
||||||
`.replace(/^\t\t/gm, '').trim();
|
`.replace(/^\t\t/gm, '').trim();
|
||||||
@@ -60,8 +60,8 @@ function generate_client(
|
|||||||
|
|
||||||
let code = `
|
let code = `
|
||||||
// This file is generated by Sapper — do not edit it!
|
// This file is generated by Sapper — do not edit it!
|
||||||
import root from '${get_file(path_to_routes, manifest_data.root)}';
|
import root from ${stringify(get_file(path_to_routes, manifest_data.root))};
|
||||||
import error from '${posixify(`${path_to_routes}/_error.html`)}';
|
import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};
|
||||||
|
|
||||||
const d = decodeURIComponent;
|
const d = decodeURIComponent;
|
||||||
|
|
||||||
@@ -73,8 +73,8 @@ function generate_client(
|
|||||||
const source = get_file(path_to_routes, component);
|
const source = get_file(path_to_routes, component);
|
||||||
|
|
||||||
return `const ${component.name} = {
|
return `const ${component.name} = {
|
||||||
js: () => import(${annotation}'${source}'),
|
js: () => import(${annotation}${stringify(source)}),
|
||||||
css: "__SAPPER_CSS_PLACEHOLDER:${component.file}__"
|
css: "__SAPPER_CSS_PLACEHOLDER:${stringify(component.file, false)}__"
|
||||||
};`;
|
};`;
|
||||||
}).join('\n')}
|
}).join('\n')}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ function generate_client(
|
|||||||
|
|
||||||
code += `
|
code += `
|
||||||
|
|
||||||
import('${sapper_dev_client}').then(client => {
|
import(${stringify(sapper_dev_client)}).then(client => {
|
||||||
client.connect(${dev_port});
|
client.connect(${dev_port});
|
||||||
});`.replace(/^\t{3}/gm, '');
|
});`.replace(/^\t{3}/gm, '');
|
||||||
}
|
}
|
||||||
@@ -129,11 +129,11 @@ function generate_server(
|
|||||||
) {
|
) {
|
||||||
const imports = [].concat(
|
const imports = [].concat(
|
||||||
manifest_data.server_routes.map(route =>
|
manifest_data.server_routes.map(route =>
|
||||||
`import * as ${route.name} from '${posixify(`${path_to_routes}/${route.file}`)}';`),
|
`import * as ${route.name} from ${stringify(posixify(`${path_to_routes}/${route.file}`))};`),
|
||||||
manifest_data.components.map(component =>
|
manifest_data.components.map(component =>
|
||||||
`import ${component.name} from '${get_file(path_to_routes, component)}';`),
|
`import ${component.name} from ${stringify(get_file(path_to_routes, component))};`),
|
||||||
`import root from '${get_file(path_to_routes, manifest_data.root)}';`,
|
`import root from ${stringify(get_file(path_to_routes, manifest_data.root))};`,
|
||||||
`import error from '${posixify(`${path_to_routes}/_error.html`)}';`
|
`import error from ${stringify(posixify(`${path_to_routes}/_error.html`))};`
|
||||||
);
|
);
|
||||||
|
|
||||||
let code = `
|
let code = `
|
||||||
@@ -164,7 +164,7 @@ function generate_server(
|
|||||||
|
|
||||||
const props = [
|
const props = [
|
||||||
`name: "${part.component.name}"`,
|
`name: "${part.component.name}"`,
|
||||||
`file: "${part.component.file}"`,
|
`file: ${stringify(part.component.file)}`,
|
||||||
`component: ${part.component.name}`
|
`component: ${part.component.name}`
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,11 @@ export function posixify(file: string) {
|
|||||||
return file.replace(/[/\\]/g, '/');
|
return file.replace(/[/\\]/g, '/');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function stringify(string: string, includeQuotes: boolean = true) {
|
||||||
|
const quoted = JSON.stringify(string);
|
||||||
|
return includeQuotes ? quoted : quoted.slice(1, -1);
|
||||||
|
}
|
||||||
|
|
||||||
export function fudge_mtime(file: string) {
|
export function fudge_mtime(file: string) {
|
||||||
// need to fudge the mtime so that webpack doesn't go doolally
|
// need to fudge the mtime so that webpack doesn't go doolally
|
||||||
const { atime, mtime } = fs.statSync(file);
|
const { atime, mtime } = fs.statSync(file);
|
||||||
|
|||||||
Reference in New Issue
Block a user