-
-
Notifications
You must be signed in to change notification settings - Fork 43
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(config): support async syncpack.config.mjs #164
Comments
Assuming const { sortOrder } = require("sort-package-json");
module.exports = {
semverRange: "^",
sortFirst: sortOrder
} All this is handled by https://github.com/cosmiconfig/cosmiconfig so there should be more info there on whether there is a way to support import/export. |
Thank you for your super fast response !! I already tried this but I get an error: // syncpack.config.cjs
const { sortOrder } = require("sort-package-json");
module.exports = {
semverRange: "^",
sortFirst: sortOrder
} Your syncpack config file contains an error
File: not known (discovered by cosmiconfig)
Error: Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/monorepo/node_modules/sort-package-json/index.js from /path/to/monorepo/syncpack.config.cjs not supported.
Instead change the require of index.js in /path/to/monorepo/syncpack.config.cjs to a dynamic import() which is available in all CommonJS modules. Any idea ? |
Try renaming the file to |
Sorry I didn't specify but my file was renamed to And when i rename to // syncpack.config.mjs
import { sortOrder } from "sort-package-json";
export default {
semverRange: "^",
sortFirst: sortOrder
};
And when i specify the config file, i get an error :
|
1Is
do you get this?
2if you take sort-package-json out of the picture completely for a moment, does it all work? // syncpack.config.mjs
export default {
semverRange: "^",
sortFirst: ['version', 'name'],
}; |
// syncpack.config.mjs
export default {
semverRange: "^",
sortFirst: ['version', 'name'],
};
|
I think we can rule out sort-package-json then. I'm not sure why this isn't working as syncpack uses cosmiconfig's default behaviour: syncpack/src/env/default-env.ts Lines 58 to 59 in 8234357
What do you get for this? node -e "console.log(require('cosmiconfig').cosmiconfigSync('syncpack').search())" This failed for me so I think .mjs is not supported in the version of cosmiconfig syncpack currently uses (8.2.0): echo 'export default {}' > syncpack.config.mjs
node -e "console.log(require('cosmiconfig').cosmiconfigSync('syncpack').load('syncpack.config.mjs'))" This worked though so I'd go this route for now: echo 'module.exports = {}' > syncpack.config.cjs
node -e "console.log(require('cosmiconfig').cosmiconfigSync('syncpack').load('syncpack.config.cjs'))" |
It seems that the 8.2.0 adds support for ESM to the asynchronous API only and removes support for ESM in the sync API |
Ok, as syncpack is at the moment then, using .cjs sync looks the most likely option. Does this work in its own? // syncpack.config.cjs
module.exports = {
semverRange: "^",
sortFirst: ['version', 'name'],
}; and with that file in place, does this find it? node -e "console.log(require('cosmiconfig').cosmiconfigSync('syncpack').load('syncpack.config.cjs'))" |
Yes it works with Any plan to migrate to the async API of cosmiconfig and add support for esm format ? |
Thank you very much for your help and your effort. I'll try to downgrade sort-package-json to test the require version or use a dynamic import if it's possible |
Released in 12.1.0. 👋 If anyone reading this finds syncpack useful, please tell people about it. |
Help Needed
Hi,
I'm trying to fetch the content of another package and put it in the
sortFirst
option, but I'm stuck.Is there a way to do that ? And Is it possible to use esm format for my config file ?
For example, something like this might work:
Thank's
The text was updated successfully, but these errors were encountered: