Skip to content
6 changes: 6 additions & 0 deletions .changeset/thirty-starfishes-smash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'create-amplify': patch
'@aws-amplify/cli-core': patch
---

update create-amplify flow to init a tsconfig that forces module context, removes creation of package.json in the amplify directory
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export abstract class PackageManagerControllerBase
const tsConfigTemplate = {
compilerOptions: {
target: 'es2022',
module: 'es2022',
module: 'preserve',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few things here.

  1. TS docs mention esnext next to preserve: You very likely want "nodenext" for modern Node.js projects and preserve or esnext for code that will be bundled . Why would we choose preserve over esnext ? (unless bundling doesn't matter here anymore).
  2. preserve was added in Typescript 5.4 . If we do this we have to bump Typescript to ^5.4.0. Including here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 1, bundling doesn't matter here aside from Functions. nodenext is the one that'll force you to specify .js file extensions (though I think there's a new compiler option coming that'll support .ts extensions and transform). preserve will not transform your module syntax, which should yield the same results when writing with ESM syntax using import/export instead of require/module.exports

for 2, bumped the minimum version

moduleDetection: 'force',
moduleResolution: 'bundler',
resolveJsonModule: true,
esModuleInterop: true,
Expand Down
2 changes: 1 addition & 1 deletion packages/create-amplify/src/amplify_project_creator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export class AmplifyProjectCreator {
'aws-cdk@^2',
'aws-cdk-lib@^2',
'constructs@^10.0.0',
'typescript@^5.0.0',
'typescript@^5.4.0',
'tsx',
'esbuild',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,6 @@ void describe('InitialProjectFileGenerator', () => {
path.join(process.cwd(), 'testDir', 'amplify'),
{ recursive: true },
]);
assert.equal(
fsMock.writeFile.mock.calls[0].arguments[0],
path.join(process.cwd(), 'testDir', 'amplify', 'package.json')
);
assert.deepStrictEqual(
JSON.parse(fsMock.writeFile.mock.calls[0].arguments[1]),
{ type: 'module' }
);
});

void it('creates default tsconfig file', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,6 @@ export class InitialProjectFileGenerator {
{ recursive: true }
);

const packageJsonContent = { type: 'module' };
await this.fsp.writeFile(
this.path.resolve(targetDir, 'package.json'),
JSON.stringify(packageJsonContent, null, 2)
);

await this.packageManagerController.initializeTsConfig(targetDir);
};
}
Loading