Skip to content

Commit 7425506

Browse files
authored
Merge pull request #425 from lifeart/fix-estree-external
2 parents a4bff8f + c66c56f commit 7425506

7 files changed

Lines changed: 64 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,6 @@ jobs:
7777

7878
- run: pnpm install --frozen-lockfile
7979

80+
- run: pnpm build
81+
8082
- run: pnpm test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// A comment before template
2+
<template>
3+
<div>hello</div>
4+
</template>

tests/unit-tests/__snapshots__/format.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
295295
"
296296
`;
297297
298+
exports[`format > config > default > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`format > config > default > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier";
300308
import { service } from "@ember/service";
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import { readFileSync } from 'node:fs';
2+
import path from 'node:path';
3+
4+
import { describe, expect, test } from 'vitest';
5+
6+
describe('build externals', () => {
7+
const distributionPath = path.resolve(
8+
import.meta.dirname,
9+
'../../dist/prettier-plugin-ember-template-tag.js',
10+
);
11+
12+
test('prettier/plugins/estree is externalized, not bundled', () => {
13+
const distribution = readFileSync(distributionPath, 'utf8');
14+
15+
// The dist should reference estree as an external dependency (require or import)
16+
expect(distribution).toMatch(
17+
/require\(["']prettier\/plugins\/estree["']\)|from\s+["']prettier\/plugins\/estree["']/,
18+
);
19+
20+
// The dist should NOT contain estree printer internals (canAttachComment is
21+
// a function from the estree printer that would be present if bundled)
22+
expect(distribution).not.toMatch(/function\s+\w*canAttachComment/);
23+
});
24+
25+
test('prettier/plugins/babel is externalized, not bundled', () => {
26+
const distribution = readFileSync(distributionPath, 'utf8');
27+
28+
expect(distribution).toMatch(
29+
/require\(["']prettier\/plugins\/babel["']\)|from\s+["']prettier\/plugins\/babel["']/,
30+
);
31+
});
32+
});

tests/unit-tests/config/__snapshots__/semi-false.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>
295295
"
296296
`;
297297
298+
exports[`config > semi: false > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`config > semi: false > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier"
300308
import { service } from "@ember/service"

tests/unit-tests/config/__snapshots__/template-export-default.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,14 @@ const three = <template>{{if true "true"}}</template>;
295295
"
296296
`;
297297
298+
exports[`config > templateExportDefault: true > it formats ../cases/gts/comment-with-template.gts 1`] = `
299+
"// A comment before template
300+
<template>
301+
<div>hello</div>
302+
</template>
303+
"
304+
`;
305+
298306
exports[`config > templateExportDefault: true > it formats ../cases/gts/complex.gts 1`] = `
299307
"import { on } from "@ember/modifier";
300308
import { service } from "@ember/service";

vite.config.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ export default defineConfig({
66
external: [
77
'content-tag',
88
'prettier',
9-
'prettier/plugins/estree.js',
10-
'prettier/plugins/babel.js',
9+
'prettier/plugins/estree',
10+
'prettier/plugins/babel',
1111
],
1212
},
1313
lib: {

0 commit comments

Comments
 (0)