Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/wacky-llamas-rule.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eddeee888/gcg-typescript-resolver-files': patch
---

Keep ts-morph project reference between watches
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,21 @@ export const postProcessFiles = ({
}
);
});
}

// 4. Apply to result files the updated content done in step 2. and 3. above
sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
const normalizedRelativePath = path.posix.relative(
cwd(),
sourceFile.getFilePath()
);
// 4. Apply to result files the updated content done in step 2. and 3. above
sourceFilesToProcess.forEach(({ sourceFile, resolverFile }) => {
const normalizedRelativePath = path.posix.relative(
cwd(),
sourceFile.getFilePath()
);

// Overwrite existing files with fixes
result.files[normalizedRelativePath] = {
...resolverFile,
content: sourceFile.getText(),
};
});
// Overwrite existing files with fixes
result.files[normalizedRelativePath] = {
...resolverFile,
content: sourceFile.getText(),
};
});
}
Comment on lines +149 to +162

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

This was sitting outside of the intended scope so we were running sourceFilesToProcess.forEach twice! i.e. doubling the work

};

/**
Expand Down
18 changes: 14 additions & 4 deletions packages/typescript-resolver-files/src/preset.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ import { logger } from './utils/index.js';

export const presetName = '@eddeee888/gcg-typescript-resolver-files';

let tsMorphProject: Project;

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Keeping a reference so we don't need to re-initialise and type-check files every run.


export const preset: Types.OutputPreset<RawPresetConfig> = {
buildGeneratesSection: async ({
schema,
Expand Down Expand Up @@ -88,10 +90,18 @@ export const preset: Types.OutputPreset<RawPresetConfig> = {
moduleNamingMode,
});

const tsMorphProject = await profiler.run(
async () => new Project(tsMorphProjectOptions),
createProfilerRunName('Initialising ts-morph project')
);
if (!tsMorphProject) {
tsMorphProject = await profiler.run(
async () => new Project(tsMorphProjectOptions),
createProfilerRunName('Initialising ts-morph project')
);
} else {
await profiler.run(async () => {
tsMorphProject
.getSourceFiles()
.forEach((sourceFile) => sourceFile.refreshFromFileSystemSync());
}, createProfilerRunName('Refreshing ts-morph project files'));
}

const typeMappersMap = await profiler.run(
async () =>
Expand Down