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

feat(esm): migrate this package to a pure ESM #252

Merged
merged 1 commit into from Dec 9, 2022

Conversation

nicojs
Copy link
Contributor

@nicojs nicojs commented Dec 5, 2022

BREAKING CHANGE: Please run node 12.20 or higher
BREAKING CHANGE: This package is now a pure esm, please read this

BREAKING CHANGE: Please run node 12.20 or higher
BREAKING CHANGE: This package is now a pure esm, please [read this](https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c)
@nicojs
Copy link
Contributor Author

nicojs commented Dec 5, 2022

Seems to work 👍

Technically a breaking change for people requiring from decktape directly: require('decktape')


// https://github.com/uxitten/polyfill/blob/master/string.polyfill.js
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/padStart
if (!String.prototype.padStart) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

"fonteditor-core": "2.1.10",
"pdf-lib": "1.17.1",
"puppeteer": "18.2.1",
"puppeteer-core": "18.2.1",
"urijs": "1.19.11"
},
"engines": {
"node": ">=12.0.0"
"node": ">=12.20"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the minimal version for ESM

@@ -226,6 +218,18 @@ process.on('unhandledRejection', error => {
});

(async () => {
const plugins = await loadAvailablePlugins(path.join(path.dirname(fileURLToPath(import.meta.url)), 'plugins'));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Loading plugins could not be done the same way dynamically without an await. I decided to move this inside the anonymous async function.

fs.accessSync(pdfDir, fs.constants.F_OK);
} catch {
fs.mkdirSync(pdfDir, { recursive: true });
async function writePdf(filename, pdf) {
Copy link
Contributor Author

@nicojs nicojs Dec 5, 2022

Choose a reason for hiding this comment

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

Moved all these functions inside the anonymous async function, because most of them seem to use the options that are now parsed at the top of the anonymous function, just after loading plugins. (no longer a global variable)


const plugins = loadAvailablePlugins(path.join(path.dirname(__filename), 'plugins'));
import chalk from 'chalk';
import chalkTemplate from 'chalk-template';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Chalk v5 seems to have split out its tagged template literal functionality into a separate package 🤷‍♂️

Copy link
Owner

@astefanutti astefanutti left a comment

Choose a reason for hiding this comment

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

That's awesome! I've given it a try and identified a couple of small specific issues. Let's merge this, and I'll work on fixing them. Maybe I'll bump the major version in the next release so it's clear that's a breaking change, even if Decktape is more a CLI than a library that is depended on.

@astefanutti astefanutti merged commit 056002f into astefanutti:master Dec 9, 2022
@nicojs nicojs deleted the esm branch December 14, 2022 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants