Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update TypeScript to latest #630

Merged
merged 10 commits into from
Aug 27, 2024
Merged
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
170 changes: 134 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/ember-auto-import/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"quick-temp": "^0.1.8",
"qunit": "^2.17.2",
"qunit-assertions-extra": "^0.8.5",
"typescript": "4.3.5"
"typescript": "5.5.3"
},
"engines": {
"node": "12.* || 14.* || >= 16"
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-auto-import/ts/analyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export default class Analyzer extends Funnel {
try {
transformSync(source, options);
} catch (err) {
if (err.name !== 'SyntaxError') {
if (err instanceof Error && err.name !== 'SyntaxError') {
Copy link
Member

Choose a reason for hiding this comment

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

I understand what you're doing here but I don't like the idea of introducing a subtle behaviour change just to work around types here. I would prefer if you worked around the types like you did later in the PR. Something like (err as unknown as {name: string})? but don't quote me on it 😂

Copy link
Contributor Author

Choose a reason for hiding this comment

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

But what's the change in behaviour here? In case of a SyntaxError it will always be an instance of Error, right? And if it's not a SyntaxError, then the if condition will not be hit either way. If feel this is the cleaner way to do this than to override the types, given that TS is actually right 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.

@mansona 👆😏

throw err;
}
debug('Ignoring an unparseable file');
Expand Down
2 changes: 1 addition & 1 deletion packages/ember-auto-import/ts/tests/analyzer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ Qmodule('analyzer', function (hooks) {
throw new Error(`expected not to get here, build was supposed to fail`);
} catch (err) {
assert.contains(
err.message,
err instanceof Error ? err.message : String(err),
'import() is only allowed to contain string literals or template string literals'
);
}
Expand Down
6 changes: 3 additions & 3 deletions packages/ember-auto-import/ts/tests/splitter-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ Qmodule('splitter', function (hooks) {
throw new Error(`expected not to get here, build was supposed to fail`);
} catch (err) {
assert.contains(
err.message,
err instanceof Error ? err.message : String(err),
'Dynamic imports must target unambiguous package names'
);
}
Expand All @@ -333,7 +333,7 @@ Qmodule('splitter', function (hooks) {
throw new Error(`expected not to get here, build was supposed to fail`);
} catch (err) {
assert.contains(
err.message,
err instanceof Error ? err.message : String(err),
'Dynamic imports must target unambiguous package names'
);
}
Expand All @@ -349,7 +349,7 @@ Qmodule('splitter', function (hooks) {
throw new Error(`expected not to get here, build was supposed to fail`);
} catch (err) {
assert.contains(
err.message,
err instanceof Error ? err.message : String(err),
`ember-auto-import does not support dynamic relative imports. "./thing" is relative. To make this work, you need to upgrade to Embroider.`
);
}
Expand Down
12 changes: 6 additions & 6 deletions packages/ember-auto-import/ts/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { join, dirname, resolve, relative, posix, isAbsolute } from 'path';
import { createHash } from 'crypto';
import { mergeWith, flatten, zip } from 'lodash';
import { writeFileSync, realpathSync, readFileSync } from 'fs';
import { compile, registerHelper } from 'handlebars';
import Handlebars from 'handlebars';
import jsStringEscape from 'js-string-escape';
import { BundleDependencies, ResolvedTemplateImport } from './splitter';
import { BuildResult, Bundler, BundlerOptions } from './bundler';
Expand All @@ -32,8 +32,8 @@ const EXTENSIONS = ['.js', '.ts', '.json'];

const debug = makeDebug('ember-auto-import:webpack');

registerHelper('js-string-escape', jsStringEscape);
registerHelper('join', function (list, connector) {
Handlebars.registerHelper('js-string-escape', jsStringEscape);
Handlebars.registerHelper('join', function (list, connector) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The API docs only show that kind of usage, and registerHelper accesses this.. Not sure why it worked before, but as soon as the compilation output from a new TS versions changed this be like (0, handlebars_1.registerHelper)('join', ...), it would lose access to this.

return list.join(connector);
});

Expand All @@ -56,9 +56,9 @@ function idToModule(id: string) {
return moduleIdMap.get(id) ?? id;
}

registerHelper('module-to-id', moduleToId);
Handlebars.registerHelper('module-to-id', moduleToId);

const entryTemplate = compile(
const entryTemplate = Handlebars.compile(
`
module.exports = (function(){
var d = _eai_d;
Expand Down Expand Up @@ -441,7 +441,7 @@ export default class WebpackBundler extends Plugin implements Bundler {
return callback(undefined, 'commonjs ' + request);
}
} catch (err) {
if (err.code !== 'MODULE_NOT_FOUND') {
if ((err as NodeJS.ErrnoException).code !== 'MODULE_NOT_FOUND') {
throw err;
}
// real package doesn't exist, so externalize it
Expand Down
2 changes: 1 addition & 1 deletion test-scenarios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"dependencies": {
"@types/qunit": "^2.11.1",
"qunit": "^2.6.1",
"ts-node": "^9.1.1",
"ts-node": "^10.9.2",
"scenario-tester": "^2.1.2",
"jsdom": "^11.11.0"
},
Expand Down
Loading