Skip to content

Add exports field to package.json - #7307

Merged
ybiquitous merged 8 commits into
v16from
add-exports-field
Nov 9, 2023
Merged

ybiquitous merged 8 commits into
v16from
add-exports-field

Conversation

@ybiquitous

@ybiquitous ybiquitous commented Nov 7, 2023 •

Copy link
Copy Markdown
Member

Which issue, if any, is this issue related to?

Closes #6258
Ref #5291

Is there anything in the PR that needs further explanation?

This Pull Request is necessary for Conditional exports (ESM and CJS).

Note: For backward compatibility, we may need to export stylelint/lib/utils/* files.
The following script can easily output many lib/utils/ settings.

Script

import path from 'node:path';

import fg from 'fast-glob';

const exports = {
	'.': {
		import: './lib/index.mjs',
		require: './lib/index.cjs',
	},
	'./package.json': './package.json',
};

const files = fg.sync('lib/utils/isStandardSyntax*.mjs', { ignore: '**/__tests__/**' });

for (const file of files) {
	const base = path.basename(file, '.mjs');
	exports[`./lib/utils/${base}`] = {
		import: `./lib/utils/${base}.mjs`,
		require: `./lib/utils/${base}.cjs`,
	};
}

console.log(JSON.stringify(exports, null, 2));

I'd like to hear feedback about exporting lib/** files. Should we export all files? I worry about frequent breaking changes in the future, if we exposed all modules (including internal ones).

Ideally, we should export utilities only through stylelint.utils, but actually we don't. Especially, isStandardSyntax* utilities are necessary to write a plugin or a custom rule.

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Use exports field in package.json to forbid unexpected API usage

3 participants