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

Improving Windows support #742

Merged
merged 7 commits into from
Mar 30, 2021
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
2 changes: 1 addition & 1 deletion packages/core/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ let d = w.define;
{{#if styles}}
if (macroCondition(!getGlobalConfig().fastboot?.isRunning)) {
{{#each styles as |stylePath| ~}}
i("{{stylePath.path}}");
i("{{js-string-escape stylePath.path}}");
{{/each}}
}
{{/if}}
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/package-name.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { isAbsolute } from 'path';

export default function absolutePackageName(specifier: string): string | undefined {
if (specifier[0] === '.' || specifier[0] === '/') {
if (specifier[0] === '.' || isAbsolute(specifier)) {
// Not an absolute specifier
return;
}
Expand Down
15 changes: 13 additions & 2 deletions packages/core/src/template-compiler-common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ export interface GlimmerSyntax {
_Ember: { FEATURES: any; ENV: any };
}

const htmlbarPathMatches = [
['htmlbars-inline-precompile', 'index.js'].join(sep),
['htmlbars-inline-precompile', 'lib', 'require-from-worker.js'].join(sep),
['htmlbars-inline-precompile', 'index'].join(sep),
['htmlbars-inline-precompile', 'lib', 'require-from-worker'].join(sep),
['ember-cli-htmlbars', 'index.js'].join(sep),
['ember-cli-htmlbars', 'lib', 'require-from-worker.js'].join(sep),
['ember-cli-htmlbars', 'index'].join(sep),
['ember-cli-htmlbars', 'lib', 'require-from-worker'].join(sep),
];

export interface TemplateCompilerParams {
// this should be the exports object from ember-template-compiler.js. It's
// "unknown" here because it changes shape in different ember versions, we
Expand Down Expand Up @@ -223,8 +234,8 @@ export class TemplateCompiler {
}
}

function matchesSourceFile(filename: string) {
return /(htmlbars-inline-precompile|ember-cli-htmlbars)\/(index|lib\/require-from-worker)(\.js)?$/.test(filename);
export function matchesSourceFile(filename: string) {
return Boolean(htmlbarPathMatches.find(match => filename.endsWith(match)));
}

function hasProperties(item: any) {
Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/write-template-compiler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { resolve } from 'path';
import { Portable, PortableHint } from './portable';
import type { NodeTemplateCompilerParams } from './template-compiler-node';
import jsStringEscape from 'js-string-escape';

export function templateCompilerModule(params: NodeTemplateCompilerParams, hints: PortableHint[]) {
let p = new Portable({ hints });
let result = p.dehydrate(params);
return {
src: [
`const { NodeTemplateCompiler } = require("${resolve(__dirname, './template-compiler-node.js')}");`,
`const { Portable } = require("${resolve(__dirname, './portable.js')}");`,
`const { NodeTemplateCompiler } = require("${jsStringEscape(
resolve(__dirname, './template-compiler-node.js')
)}");`,
`const { Portable } = require("${jsStringEscape(resolve(__dirname, './portable.js'))}");`,
`let p = new Portable({ hints: ${JSON.stringify(hints, null, 2)} });`,
`module.exports = new NodeTemplateCompiler(p.hydrate(${JSON.stringify(result.value, null, 2)}))`,
].join('\n'),
Expand Down
31 changes: 31 additions & 0 deletions packages/core/tests/template-compiler-common.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { matchesSourceFile } from '../src/template-compiler-common';

describe('template-compiler-common', () => {
test('that matchesSourceFile correctly matches paths for both Windows and Unix', () => {
expect(matchesSourceFile('/htmlbars-inline-precompile/index.js')).toBeTruthy;
expect(matchesSourceFile('/htmlbars-inline-precompile/index')).toBeTruthy;
expect(matchesSourceFile('/htmlbars-inline-precompile/lib/require-from-worker.js')).toBeTruthy;
expect(matchesSourceFile('/htmlbars-inline-precompile/lib/require-from-worker')).toBeTruthy;

expect(matchesSourceFile('/ember-cli-htmlbars/index.js')).toBeTruthy;
expect(matchesSourceFile('/ember-cli-htmlbars/index')).toBeTruthy;
expect(matchesSourceFile('/ember-cli-htmlbars/lib/require-from-worker.js')).toBeTruthy;
expect(matchesSourceFile('/ember-cli-htmlbars/lib/require-from-worker')).toBeTruthy;

// Windows paths
expect(matchesSourceFile('\\htmlbars-inline-precompile\\index.js')).toBeTruthy;
expect(matchesSourceFile('\\htmlbars-inline-precompile\\index')).toBeTruthy;
expect(matchesSourceFile('\\htmlbars-inline-precompile\\lib\\require-from-worker.js')).toBeTruthy;
expect(matchesSourceFile('\\htmlbars-inline-precompile\\lib\\require-from-worker')).toBeTruthy;

expect(matchesSourceFile('\\ember-cli-htmlbars\\index.js')).toBeTruthy;
expect(matchesSourceFile('\\ember-cli-htmlbars\\index')).toBeTruthy;
expect(matchesSourceFile('\\ember-cli-htmlbars\\lib\\require-from-worker.js')).toBeTruthy;
expect(matchesSourceFile('\\ember-cli-htmlbars\\lib\\require-from-worker')).toBeTruthy;

expect(matchesSourceFile('/ember-cli-htmlbars/')).toBeFalsy;
expect(matchesSourceFile('/htmlbars-inline-precompile/')).toBeFalsy;
expect(matchesSourceFile('')).toBeFalsy;
expect(matchesSourceFile('badstring')).toBeFalsy;
});
});