diff --git a/.changeset/hip-monkeys-glow.md b/.changeset/hip-monkeys-glow.md new file mode 100644 index 000000000000..ad849050f12b --- /dev/null +++ b/.changeset/hip-monkeys-glow.md @@ -0,0 +1,7 @@ +--- +"create-cloudflare": patch +--- + +.gitignore files were not included in our templates due to npm/npm#3763 + +we now workaround this issue and ensure C3 templates include a .gitignore file diff --git a/packages/create-cloudflare/.gitignore b/packages/create-cloudflare/.gitignore index 39dcb2e5b894..0dc5f7c6bace 100644 --- a/packages/create-cloudflare/.gitignore +++ b/packages/create-cloudflare/.gitignore @@ -8,3 +8,6 @@ create-cloudflare-*.tgz templates/**/package-lock.json templates/**/yarn.lock templates/**/pnpm-lock.yaml + +# the build step renames .gitignore files to __dot__gitignore +templates/**/__dot__gitignore diff --git a/packages/create-cloudflare/e2e-tests/workers.test.ts b/packages/create-cloudflare/e2e-tests/workers.test.ts index 7acca2171a4b..1825a19708ae 100644 --- a/packages/create-cloudflare/e2e-tests/workers.test.ts +++ b/packages/create-cloudflare/e2e-tests/workers.test.ts @@ -44,6 +44,9 @@ describe.skipIf(frameworkToTest || isQuarantineMode())( // Relevant project files should have been created expect(projectPath).toExist(); + const gitignorePath = join(projectPath, ".gitignore"); + expect(gitignorePath).toExist(); + const pkgJsonPath = join(projectPath, "package.json"); expect(pkgJsonPath).toExist(); diff --git a/packages/create-cloudflare/package.json b/packages/create-cloudflare/package.json index e5c9599e9b5d..169ab0d121f2 100644 --- a/packages/create-cloudflare/package.json +++ b/packages/create-cloudflare/package.json @@ -64,6 +64,7 @@ "dns2": "^2.1.0", "esbuild": "^0.17.12", "execa": "^7.1.1", + "glob": "^10.3.3", "haikunator": "^2.1.2", "log-update": "^5.0.1", "open": "^8.4.0", diff --git a/packages/create-cloudflare/scripts/build.ts b/packages/create-cloudflare/scripts/build.ts index b05f8c7c9c13..b56148a6eb42 100644 --- a/packages/create-cloudflare/scripts/build.ts +++ b/packages/create-cloudflare/scripts/build.ts @@ -1,5 +1,6 @@ import { build, context, BuildOptions } from "esbuild"; import { cp } from "fs/promises"; +import * as glob from "glob"; const run = async () => { const argv = process.argv.slice(2); @@ -20,6 +21,15 @@ const run = async () => { recursive: true, force: true, }); + + // npm pack doesn't include .gitignore files (see https://github.com/npm/npm/issues/3763) + // To workaround, copy all ".gitignore" files as "__dot__gitignore" so npm pack includes them + // The latter has been added to the project's .gitignore file + // This renaming will be reversed when each template is used + // We can continue to author ".gitignore" files in each template + for (const filepath of glob.sync("templates/**/.gitignore")) { + await cp(filepath, filepath.replace(".gitignore", "__dot__gitignore")); + } }; const runWatch = async () => { diff --git a/packages/create-cloudflare/src/workers.ts b/packages/create-cloudflare/src/workers.ts index 1765aceca490..381085fe8cf1 100644 --- a/packages/create-cloudflare/src/workers.ts +++ b/packages/create-cloudflare/src/workers.ts @@ -1,4 +1,12 @@ -import { readFile, writeFile, mkdtemp, cp, rm, readdir } from "fs/promises"; +import { + readFile, + writeFile, + mkdtemp, + cp, + rm, + readdir, + rename, +} from "fs/promises"; import { tmpdir } from "os"; import { resolve, join } from "path"; import { chdir } from "process"; @@ -81,6 +89,9 @@ async function copyFiles(ctx: Context) { // copy template files updateStatus(`Copying files from "${template}" template`); await cp(srcdir, destdir, { recursive: true }); + + // reverse renaming from build step + await rename(join(destdir, "__dot__gitignore"), join(destdir, ".gitignore")); } async function copyExistingWorkerFiles(ctx: Context) { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index cac0143d0c60..5261f5061c5a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -510,6 +510,9 @@ importers: execa: specifier: ^7.1.1 version: 7.1.1 + glob: + specifier: ^10.3.3 + version: 10.3.10 haikunator: specifier: ^2.1.2 version: 2.1.2 @@ -4391,7 +4394,6 @@ packages: strip-ansi-cjs: /strip-ansi@6.0.1 wrap-ansi: 8.1.0 wrap-ansi-cjs: /wrap-ansi@7.0.0 - dev: false /@istanbuljs/load-nyc-config@1.1.0: resolution: {integrity: sha512-VjeHSlIzpv/NyD3N0YuHfXOPDIixcA1q2ZV98wsMqcYlPmv2n3Yb2lYP9XMElnaFVXg5A7YLTeLu6V84uQDjmQ==} @@ -4859,7 +4861,6 @@ packages: resolution: {integrity: sha512-+1VkjdD0QBLPodGrJUeqarH8VAIvQODIbwh9XpP5Syisf7YoQgsJKPNFoqqLQlu+VQ/tVSshMR6loPMn8U+dPg==} engines: {node: '>=14'} requiresBuild: true - dev: false optional: true /@pkgr/utils@2.4.1: @@ -9982,7 +9983,6 @@ packages: dependencies: cross-spawn: 7.0.3 signal-exit: 4.0.2 - dev: false /format@0.2.2: resolution: {integrity: sha512-wzsgA6WOq+09wrU1tsJ09udeR/YZRaeArL9e1wPbFg3GG2yDnC2ldKpxs4xunpFF9DgqCqOIra3bc1HWrJ37Ww==} @@ -10222,17 +10222,16 @@ packages: /glob-to-regexp@0.4.1: resolution: {integrity: sha512-lkX1HJXwyMcprw/5YUZc2s7DrpAiHB21/V+E1rHUrVNokkvB6bqMzT0VfV6/86ZNabt1k14YOIaT7nDvOX3Iiw==} - /glob@10.3.0: - resolution: {integrity: sha512-AQ1/SB9HH0yCx1jXAT4vmCbTOPe5RQ+kCurjbel5xSCGhebumUv+GJZfa1rEqor3XIViqwSEmlkZCQD43RWrBg==} + /glob@10.3.10: + resolution: {integrity: sha512-fa46+tv1Ak0UPK1TOy/pZrIybNNt4HCv7SDzwyfiOZkvZLEbjsZkJBPtDHVshZjbecAoAGSC20MjLDG/qr679g==} engines: {node: '>=16 || 14 >=14.17'} hasBin: true dependencies: foreground-child: 3.1.1 - jackspeak: 2.2.1 + jackspeak: 2.3.6 minimatch: 9.0.1 minipass: 6.0.2 - path-scurry: 1.9.2 - dev: false + path-scurry: 1.10.1 /glob@7.2.0: resolution: {integrity: sha512-lmLf6gtyrPq8tTjSmrO94wBeQbFR3HbLHbuyD69wuyQkImp2hWqMGB47OX65FBkPffO641IP9jWa1z4ivqG26Q==} @@ -11412,14 +11411,13 @@ packages: resolution: {integrity: sha512-Fu/GO3MFX6Hwd+QF1/BFjoFpPQKh2Bu4DtBdse5kECcUwldNBrZqgwq0IariLrP67iADGlzkHIlOWwJ8F4SJ4A==} dev: true - /jackspeak@2.2.1: - resolution: {integrity: sha512-MXbxovZ/Pm42f6cDIDkl3xpwv1AGwObKwfmjs2nQePiy85tP3fatofl3FC1aBsOtP/6fq5SbtgHwWcMsLP+bDw==} + /jackspeak@2.3.6: + resolution: {integrity: sha512-N3yCS/NegsOBokc8GAdM8UcmfsKiSS8cipheD/nivzr700H+nsMOxJjQnvwOcRYVuFkdH0wGUvW2WbXGmrZGbQ==} engines: {node: '>=14'} dependencies: '@isaacs/cliui': 8.0.2 optionalDependencies: '@pkgjs/parseargs': 0.11.0 - dev: false /javascript-stringify@2.1.0: resolution: {integrity: sha512-JVAfqNPTvNq3sB/VHQJAFxN/sPgKnsKrCwyRt15zwNCdrMMJDdcEOdubuy+DuJYYdm0ox1J4uzEuYKkN+9yhVg==} @@ -12332,7 +12330,6 @@ packages: /lru-cache@9.1.2: resolution: {integrity: sha512-ERJq3FOzJTxBbFjZ7iDs+NiK4VI9Wz+RdrrAB8dio1oV+YvdPzUEE4QNiT2VD51DkIbCYRUUzCRkssXCHqSnKQ==} engines: {node: 14 || >=16.14} - dev: false /lz-string@1.5.0: resolution: {integrity: sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==} @@ -13028,7 +13025,6 @@ packages: /minipass@6.0.2: resolution: {integrity: sha512-MzWSV5nYVT7mVyWCwn2o7JH13w2TBRmmSqSRCKzTw+lmft9X4z+3wjvs06Tzijo5z4W/kahUCDpRXTF+ZrmF/w==} engines: {node: '>=16 || 14 >=14.17'} - dev: false /minizlib@2.1.2: resolution: {integrity: sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==} @@ -13874,13 +13870,12 @@ packages: /path-parse@1.0.7: resolution: {integrity: sha512-LDJzPVEEEPR+y48z93A0Ed0yXb8pAByGWo/k5YYdYgpY2/2EsOsksJrq7lOHxryrVOn1ejG6oAp8ahvOIQD8sw==} - /path-scurry@1.9.2: - resolution: {integrity: sha512-qSDLy2aGFPm8i4rsbHd4MNyTcrzHFsLQykrtbuGRknZZCBBVXSv2tSCDN2Cg6Rt/GFRw8GoW9y9Ecw5rIPG1sg==} + /path-scurry@1.10.1: + resolution: {integrity: sha512-MkhCqzzBEpPvxxQ71Md0b1Kk51W01lrYvlMzSUaIzNsODdd7mqhiimSZlr+VegAz5Z6Vzt9Xg2ttE//XBhH3EQ==} engines: {node: '>=16 || 14 >=14.17'} dependencies: lru-cache: 9.1.2 minipass: 6.0.2 - dev: false /path-to-regexp@0.1.7: resolution: {integrity: sha512-5DFkuoqlv1uYQKxy8omFBeJPQcdoE07Kv2sferDCrAq1ohOU+MSDswDIbnx3YAM60qIOnYa53wBhXW0EbMonrQ==} @@ -15000,7 +14995,7 @@ packages: engines: {node: '>=14'} hasBin: true dependencies: - glob: 10.3.0 + glob: 10.3.10 dev: false /roarr@7.11.0: @@ -15350,7 +15345,6 @@ packages: /signal-exit@4.0.2: resolution: {integrity: sha512-MY2/qGx4enyjprQnFaZsHib3Yadh3IXyV2C321GY0pjGfVBu4un0uDJkwgdxqO+Rdx8JMT8IfJIRwbYVz3Ob3Q==} engines: {node: '>=14'} - dev: false /sisteransi@1.0.5: resolution: {integrity: sha512-bLGGlR1QxBcynn2d5YmDX4MGjlZvy2MRBDRNHLJ8VI6l6+9FUiyTFNJ0IveOSP0bcXgVDPRcfGqA0pjaqUpfVg==}