-
-
Notifications
You must be signed in to change notification settings - Fork 37
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
feat(utilities): add possibility to import single functions by appending them to the import path. #454
Conversation
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Granted even CJS didn't work before my commit above this review, this PR still needs more work.
Create a file on the root of the repository called test.cjs
with content:
/* eslint-disable @typescript-eslint/no-var-requires */
const { isFunction } = require('@sapphire/utilities/isFunction');
console.log(isFunction(() => undefined));
then run it with node test.cjs
. This will return true
as expected.
However doing the same with test.mjs
and content:
import { isFunction } from '@sapphire/utilities/isFunction';
console.log(isFunction(() => undefined));
will give:
node file.mjs
file:///Users/favna/workspace/sapphire/utilities/file.mjs:1
import { isFunction } from '@sapphire/utilities/isFunction';
^^^^^^^^^^
SyntaxError: Named export 'isFunction' not found. The requested module '@sapphire/utilities/isFunction' is a CommonJS module, which may not support all module.exports as named exports.
CommonJS modules can always be imported via the default export, for example using:
import pkg from '@sapphire/utilities/isFunction';
const { isFunction } = pkg;
at ModuleJob._instantiate (node:internal/modules/esm/module_job:123:21)
at async ModuleJob.run (node:internal/modules/esm/module_job:189:5)
at async Promise.all (index 0)
at async ESMLoader.import (node:internal/modules/esm/loader:528:24)
at async loadESM (node:internal/process/esm_loader:91:5)
at async handleMainPromise (node:internal/modules/run_main:65:12)
Node.js v18.8.0
And lastly, TS is also broken, again with a similar file this time file.ts
:
import { isFunction } from '@sapphire/utilities/isFunction';
console.log(isFunction(() => undefined));
This gives a compiler error:
Cannot find module '@sapphire/utilities/isFunction' or its corresponding type declarations.ts(2307)
@sapphire/utilities
packages/discord.js-utilities/src/lib/MessagePrompter/strategies/MessagePrompterBaseStrategy.ts
Outdated
Show resolved
Hide resolved
packages/discord.js-utilities/src/lib/PaginatedMessages/PaginatedMessage.ts
Outdated
Show resolved
Hide resolved
packages/discord.js-utilities/src/lib/PaginatedMessages/PaginatedMessage.ts
Outdated
Show resolved
Hide resolved
packages/discord.js-utilities/src/lib/PaginatedMessages/utils.ts
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
blocking until #468 is merged
fixes #452
tsup was bunding the dts in one file and has no option to disable it. So I've used
tsc
to build the types files.