Skip to content

Commit

Permalink
Merge pull request #742 from thoov/windows-support
Browse files Browse the repository at this point in the history
Improving Windows support
  • Loading branch information
ef4 authored Mar 30, 2021
2 parents 00db51a + a9cccbd commit 9660ab9
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 6 deletions.
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
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;
});
});
4 changes: 3 additions & 1 deletion packages/shared-internals/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

0 comments on commit 9660ab9

Please sign in to comment.