Skip to content

Commit

Permalink
fix: resolve punycode deprecation notice (#3537)
Browse files Browse the repository at this point in the history
* chore: fix `punycode` warning

* chore: changeset

* Update .changeset/seven-balloons-kick.md

* chore: release to npm

* chore: clean up CLI paths

* chore: added overrides for templates

chore: added overrides for templates

* chore: pls resolve

* Revert "chore: pls resolve"

This reverts commit 18073b2.

* chore: corrected overrides

* Update .github/workflows/pr-release.yaml

* Update packages/create-fuels/src/cli.ts

* Update .changeset/seven-balloons-kick.md

---------

Co-authored-by: Anderson Arboleya <[email protected]>
  • Loading branch information
petertonysmith94 and arboleya authored Jan 6, 2025
1 parent a278e71 commit 10612b2
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 86 deletions.
5 changes: 5 additions & 0 deletions .changeset/seven-balloons-kick.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"create-fuels": patch
---

fix: resolve `punycode` deprecation notice
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@
},
"pnpm": {
"overrides": {
"whatwg-url": "14.1.0",
"cross-fetch": "4.0.0"
}
}
Expand Down
16 changes: 15 additions & 1 deletion packages/create-fuels/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,24 @@ export const runScaffoldCli = async ({
const packageJsonPath = join(projectPath, 'package.json');
const packageJsonContents = readFileSync(packageJsonPath, 'utf-8');
const fuelsVersion = getPackageVersion(args);
const newPackageJsonContents = packageJsonContents
let newPackageJsonContents = packageJsonContents
.replace(`pnpm run prebuild`, packageManager.run('prebuild'))
.replace(`"fuels": "${versions.FUELS}"`, `"fuels": "${fuelsVersion}"`);

// TODO: remove once upgraded to `graphql-request@v7`
// https://github.com/FuelLabs/fuels-ts/issues/3546
if (packageManager.name === 'pnpm') {
let newPackageJsonObject = JSON.parse(newPackageJsonContents);
newPackageJsonObject = {
...newPackageJsonObject,
overrides: undefined,
pnpm: {
overrides: newPackageJsonObject.overrides,
},
};
newPackageJsonContents = JSON.stringify(newPackageJsonObject, null, 2);
}

writeFileSync(packageJsonPath, newPackageJsonContents);

// Rewrite the README.md file
Expand Down
59 changes: 55 additions & 4 deletions packages/create-fuels/test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ describe('CLI', { timeout: 15_000 }, () => {
args,
});

const fuelToolchainPath = join(paths.projectRoot, 'fuel-toolchain.toml');
const fuelToolchain = readFileSync(fuelToolchainPath, 'utf-8');
const fuelToolchain = readFileSync(paths.fuelToolchainPath, 'utf-8');
const parsedFuelToolchain = toml.parse(fuelToolchain);

const { toolchain, components } = parsedFuelToolchain;
Expand All @@ -107,8 +106,7 @@ describe('CLI', { timeout: 15_000 }, () => {
args,
});

const packageJsonPath = join(paths.projectRoot, 'package.json');
const packageJson = readFileSync(packageJsonPath, 'utf-8');
const packageJson = readFileSync(paths.packageJsonPath, 'utf-8');
expect(packageJson).toContain('bun run prebuild');

const readmePath = join(paths.projectRoot, 'README.md');
Expand Down Expand Up @@ -164,4 +162,57 @@ describe('CLI', { timeout: 15_000 }, () => {
expect(log).toHaveBeenCalledWith(` - ${template}`);
}
});

test('should have a package.json with overrides', async () => {
const args = generateArgv({
projectName: paths.projectRoot,
template: paths.templateName,
});

vi.spyOn(doesTemplateExistMod, 'doesTemplateExist').mockReturnValueOnce(true);

await runScaffoldCli({
program: setupProgram(),
args,
});

const packageJson = readFileSync(paths.packageJsonPath, 'utf-8');
const packageJsonObject = JSON.parse(packageJson);

expect(packageJsonObject).toEqual(
expect.objectContaining({
overrides: expect.any(Object),
})
);
});

test('should rewrite overrides for pnpm', async () => {
process.env.npm_config_user_agent = 'pnpm';

const args = generateArgv({
projectName: paths.projectRoot,
template: paths.templateName,
});

vi.spyOn(doesTemplateExistMod, 'doesTemplateExist').mockReturnValueOnce(true);

await runScaffoldCli({
program: setupProgram(),
args,
});

const packageJson = readFileSync(paths.packageJsonPath, 'utf-8');
const packageJsonObject = JSON.parse(packageJson);

expect(packageJsonObject.overrides).toBeUndefined();
expect(packageJsonObject).toEqual(
expect.objectContaining({
pnpm: {
overrides: expect.any(Object),
},
})
);

delete process.env.npm_config_user_agent;
});
});
2 changes: 1 addition & 1 deletion packages/create-fuels/test/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ describe('`create fuels` package integrity', () => {
expect(createFuelsError).toBeUndefined();
const actualTemplateFiles = await getAllFiles(paths.projectRoot);
expect(actualTemplateFiles.sort()).toEqual(expectedTemplateFiles.sort());
const packageJson = readFileSync(paths.projectPackageJson, 'utf-8');
const packageJson = readFileSync(paths.packageJsonPath, 'utf-8');
expect(packageJson).toEqual(expect.stringMatching(expectedPackageJsonInstall));
},
{ timeout: 30000 }
Expand Down
9 changes: 6 additions & 3 deletions packages/create-fuels/test/utils/bootstrapProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { rewriteTemplateFiles } from '../../src/lib/rewriteTemplateFiles';
export type ProjectPaths = {
// Project paths
projectRoot: string;
projectPackageJson: string;
packageJsonPath: string;
fuelToolchainPath: string;

// Template paths
templateName: string;
Expand All @@ -28,7 +29,8 @@ export const bootstrapProject = (testFilepath: string, template: string = 'vite'
// Project paths
const projectName = `__temp__project_${testFilename}_${new Date().getTime()}`;
const projectRoot = join(testDir, projectName);
const projectPackageJson = join(projectRoot, 'package.json');
const packageJsonPath = join(projectRoot, 'package.json');
const fuelToolchainPath = join(projectRoot, 'fuel-toolchain.toml');

// Template paths
const templateName = `__temp__template_${template}_${testFilename}_${new Date().getTime()}`;
Expand All @@ -38,7 +40,8 @@ export const bootstrapProject = (testFilepath: string, template: string = 'vite'
return {
// Project paths
projectRoot,
projectPackageJson,
packageJsonPath,
fuelToolchainPath,

// Template paths
templateName,
Expand Down
Loading

0 comments on commit 10612b2

Please sign in to comment.