Skip to content

Commit f2bce35

Browse files
authored
chore(gatsby-parcel-config): stabilize ts compilation parcel output (#34943)
1 parent 2cf474b commit f2bce35

File tree

6 files changed

+74
-1
lines changed

6 files changed

+74
-1
lines changed

packages/gatsby-parcel-config/lib/index.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"*.{xml,rss,atom}": ["@parcel/transformer-xml"],
2424
"url:*": ["...", "@parcel/transformer-raw"]
2525
},
26-
"namers": ["@parcel/namer-default"],
26+
"namers": ["@gatsbyjs/parcel-namer-relative-to-cwd", "@parcel/namer-default"],
2727
"runtimes": [
2828
"@parcel/runtime-js",
2929
"@parcel/runtime-browser-hmr",

packages/gatsby-parcel-config/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
"parcel": "2.x"
1414
},
1515
"dependencies": {
16+
"@gatsbyjs/parcel-namer-relative-to-cwd": "0.0.2",
1617
"@parcel/bundler-default": "^2.3.1",
1718
"@parcel/compressor-raw": "^2.3.1",
1819
"@parcel/namer-default": "^2.3.1",
@@ -31,6 +32,7 @@
3132
"@parcel/transformer-react-refresh-wrap": "^2.3.1"
3233
},
3334
"parcelDependencies": {
35+
"@gatsbyjs/parcel-namer-relative-to-cwd": "0.0.2",
3436
"@parcel/optimizer-data-url": "^2.3.1",
3537
"@parcel/packager-raw-url": "^2.3.1",
3638
"@parcel/packager-ts": "^2.3.1",

packages/gatsby/src/utils/parcel/__tests__/compile-gatsby-files.ts

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { readFile, remove, pathExists } from "fs-extra"
1313
const dir = {
1414
js: `${__dirname}/fixtures/js`,
1515
ts: `${__dirname}/fixtures/ts`,
16+
tsOnlyInLocal: `${__dirname}/fixtures/ts-only-in-local-plugin`,
1617
}
1718

1819
jest.mock(`@parcel/core`, () => {
@@ -37,6 +38,15 @@ interface IMockedParcel extends Parcel {
3738
options: unknown
3839
}
3940

41+
let cwdToRestore
42+
beforeAll(() => {
43+
cwdToRestore = process.cwd()
44+
})
45+
46+
afterAll(() => {
47+
process.chdir(cwdToRestore)
48+
})
49+
4050
describe(`gatsby file compilation`, () => {
4151
describe(`constructBundler`, () => {
4252
it(`should construct Parcel relative to passed directory`, () => {
@@ -60,6 +70,7 @@ describe(`gatsby file compilation`, () => {
6070
describe(`compileGatsbyFiles`, () => {
6171
describe(`js files are not touched`, () => {
6272
beforeAll(async () => {
73+
process.chdir(dir.js)
6374
await remove(`${dir.js}/.cache`)
6475
await compileGatsbyFiles(dir.js)
6576
})
@@ -81,6 +92,7 @@ describe(`gatsby file compilation`, () => {
8192

8293
describe(`ts files are compiled`, () => {
8394
beforeAll(async () => {
95+
process.chdir(dir.ts)
8496
await remove(`${dir.ts}/.cache`)
8597
await compileGatsbyFiles(dir.ts)
8698
})
@@ -105,5 +117,31 @@ describe(`gatsby file compilation`, () => {
105117
expect(compiledGatsbyNode).toContain(`I am working!`)
106118
})
107119
})
120+
121+
describe(`ts only in local plugin files are compiled and outputted where expected`, () => {
122+
beforeAll(async () => {
123+
process.chdir(dir.tsOnlyInLocal)
124+
await remove(`${dir.tsOnlyInLocal}/.cache`)
125+
await compileGatsbyFiles(dir.tsOnlyInLocal)
126+
})
127+
128+
it(`should compile gatsby-config.ts`, async () => {
129+
const compiledGatsbyConfig = await readFile(
130+
`${dir.tsOnlyInLocal}/.cache/compiled/plugins/gatsby-plugin-local/gatsby-config.js`,
131+
`utf-8`
132+
)
133+
134+
expect(compiledGatsbyConfig).toContain(`gatsby-config is working`)
135+
})
136+
137+
it(`should compile gatsby-node.ts`, async () => {
138+
const compiledGatsbyNode = await readFile(
139+
`${dir.tsOnlyInLocal}/.cache/compiled/plugins/gatsby-plugin-local/gatsby-node.js`,
140+
`utf-8`
141+
)
142+
143+
expect(compiledGatsbyNode).toContain(`gatsby-node is working`)
144+
})
145+
})
108146
})
109147
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
console.log(`gatsby-config is working`)
2+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(`gatsby-node is working`)

yarn.lock

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,15 @@
16711671
unique-filename "^1.1.1"
16721672
which "^1.3.1"
16731673

1674+
"@gatsbyjs/[email protected]":
1675+
version "0.0.2"
1676+
resolved "https://registry.yarnpkg.com/@gatsbyjs/parcel-namer-relative-to-cwd/-/parcel-namer-relative-to-cwd-0.0.2.tgz#e1586f1796aa773e53e0909025ea16e423c14391"
1677+
integrity sha512-ZeGxCbx13+zjpE/0HuJ/tjox9zfiYq9fGoAAi+RHP5vHSJCmJVO5hZbexQ/umlUyAkkkzC4p1WIpw1cYQTA8SA==
1678+
dependencies:
1679+
"@babel/runtime" "^7.15.4"
1680+
"@parcel/plugin" "2.3.1"
1681+
gatsby-core-utils "^3.8.2"
1682+
16741683
"@gatsbyjs/reach-router@^1.3.6":
16751684
version "1.3.6"
16761685
resolved "https://registry.yarnpkg.com/@gatsbyjs/reach-router/-/reach-router-1.3.6.tgz#4e8225836959be247890b66f21a3198a0589e34d"
@@ -11228,6 +11237,27 @@ gather-stream@^1.0.0:
1122811237
version "1.0.0"
1122911238
resolved "https://registry.yarnpkg.com/gather-stream/-/gather-stream-1.0.0.tgz#b33994af457a8115700d410f317733cbe7a0904b"
1123011239

11240+
gatsby-core-utils@^3.8.2:
11241+
version "3.8.2"
11242+
resolved "https://registry.yarnpkg.com/gatsby-core-utils/-/gatsby-core-utils-3.8.2.tgz#9c2869f93a740d20536b1e92c8020efd85d43e5f"
11243+
integrity sha512-UwANr9yd8ayLinPDoRbU/rRgoOBOS715qe2LYCxq6hAtRabHWTEM8Vj0wh7LmyVGexx8MFgvp2NKikG2TZ5pzQ==
11244+
dependencies:
11245+
"@babel/runtime" "^7.15.4"
11246+
ci-info "2.0.0"
11247+
configstore "^5.0.1"
11248+
fastq "^1.13.0"
11249+
file-type "^16.5.3"
11250+
fs-extra "^10.0.0"
11251+
got "^11.8.3"
11252+
import-from "^4.0.0"
11253+
lmdb "^2.1.7"
11254+
lock "^1.1.0"
11255+
node-object-hash "^2.3.10"
11256+
proper-lockfile "^4.1.2"
11257+
resolve-from "^5.0.0"
11258+
tmp "^0.2.1"
11259+
xdg-basedir "^4.0.0"
11260+
1123111261
gauge@~2.7.3:
1123211262
version "2.7.4"
1123311263
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"

0 commit comments

Comments
 (0)