From 21e7a77ad2368c1322e2f6a6e4c631351e1cc0be Mon Sep 17 00:00:00 2001 From: Christian Bromann Date: Tue, 23 Jan 2024 11:21:33 -0800 Subject: [PATCH] chore(build): improve build process (#461) * chore(build): improve build process * remove comment --- package-lock.json | 51 ++++++++++++++++++++++++++++++++++++++++------- package.json | 5 +++-- rollup.config.mjs | 11 +++++----- src/index.ts | 1 + src/util.ts | 7 ++++--- 5 files changed, 57 insertions(+), 18 deletions(-) diff --git a/package-lock.json b/package-lock.json index 2acc220..9f3b4b0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,6 +11,7 @@ "devDependencies": { "@ionic/prettier-config": "^4.0.0", "@rollup/plugin-node-resolve": "^15.0.0", + "@rollup/plugin-typescript": "^11.1.6", "@stencil/core": "^4.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.2.0", @@ -1418,10 +1419,36 @@ } } }, + "node_modules/@rollup/plugin-typescript": { + "version": "11.1.6", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", + "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", + "dev": true, + "dependencies": { + "@rollup/pluginutils": "^5.1.0", + "resolve": "^1.22.1" + }, + "engines": { + "node": ">=14.0.0" + }, + "peerDependencies": { + "rollup": "^2.14.0||^3.0.0||^4.0.0", + "tslib": "*", + "typescript": ">=3.7.0" + }, + "peerDependenciesMeta": { + "rollup": { + "optional": true + }, + "tslib": { + "optional": true + } + } + }, "node_modules/@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", "dev": true, "dependencies": { "@types/estree": "^1.0.0", @@ -1432,7 +1459,7 @@ "node": ">=14.0.0" }, "peerDependencies": { - "rollup": "^1.20.0||^2.0.0||^3.0.0" + "rollup": "^1.20.0||^2.0.0||^3.0.0||^4.0.0" }, "peerDependenciesMeta": { "rollup": { @@ -10362,10 +10389,20 @@ "resolve": "^1.22.1" } }, + "@rollup/plugin-typescript": { + "version": "11.1.6", + "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-11.1.6.tgz", + "integrity": "sha512-R92yOmIACgYdJ7dJ97p4K69I8gg6IEHt8M7dUBxN3W6nrO8uUxX5ixl0yU/N3aZTi8WhPuICvOHXQvF6FaykAA==", + "dev": true, + "requires": { + "@rollup/pluginutils": "^5.1.0", + "resolve": "^1.22.1" + } + }, "@rollup/pluginutils": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.0.2.tgz", - "integrity": "sha512-pTd9rIsP92h+B6wWwFbW8RkZv4hiR/xKsqre4SIuAOaOEQRxi0lqLke9k2/7WegC85GgUs9pjmOjCUi3In4vwA==", + "version": "5.1.0", + "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.0.tgz", + "integrity": "sha512-XTIWOPPcpvyKI6L1NHo0lFlCyznUEyPmPY1mc3KpPVDYulHSTvyeLNVW00QTLIAFNhR3kYnJTQHeGqU4M3n09g==", "dev": true, "requires": { "@types/estree": "^1.0.0", diff --git a/package.json b/package.json index 9ab4b1e..9d7ed5f 100644 --- a/package.json +++ b/package.json @@ -17,8 +17,8 @@ "prettier": "npm run prettier.base -- --write", "prettier.base": "prettier --cache 'src/**/*.ts'", "prettier.dry-run": "npm run prettier.base -- --list-different", - "build": "npm run prebuild && tsc && npm run rollup", - "watch": "tsc --watch", + "build": "npm run prebuild && npm run rollup", + "watch": "npm run rollup -- --watch", "rollup": "rollup -c rollup.config.mjs", "version": "npm run build", "release": "np", @@ -32,6 +32,7 @@ "devDependencies": { "@ionic/prettier-config": "^4.0.0", "@rollup/plugin-node-resolve": "^15.0.0", + "@rollup/plugin-typescript": "^11.1.6", "@stencil/core": "^4.0.0", "@types/jest": "^29.0.0", "@types/node": "^20.2.0", diff --git a/rollup.config.mjs b/rollup.config.mjs index e3e655a..85c4b94 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -1,20 +1,19 @@ -import { createRequire } from 'node:module'; +import fs from 'node:fs/promises' import pluginSass from './rollup.plugin.sass.mjs'; +import typescript from '@rollup/plugin-typescript'; import rollupResolve from '@rollup/plugin-node-resolve'; -// require `package.json` in order to use its 'main' and 'module' fields to tell rollup where to output the generated -// bundles -const require = createRequire(import.meta.url); -const pkg = require('./package.json'); +const pkg = JSON.parse((await fs.readFile('./package.json'))); /** * Generate an ESM and a CJS output bundle */ export default { // the input is expected to exist at this location as a result of running the typescript compiler - input: 'dist/index.js', + input: 'src/index.ts', plugins: [ + typescript(), pluginSass(), rollupResolve({ preferBuiltins: true diff --git a/src/index.ts b/src/index.ts index 70c1f83..ccbef75 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ import { type LegacyException, type LegacyResult, render } from 'sass'; + import * as d from './declarations'; import { loadDiagnostic } from './diagnostics'; import { createResultsId, getRenderOptions, usePlugin } from './util'; diff --git a/src/util.ts b/src/util.ts index 1f0a976..23e696d 100644 --- a/src/util.ts +++ b/src/util.ts @@ -1,7 +1,8 @@ +import path from 'node:path'; +import type { LegacyAsyncImporter, LegacyImporterResult } from 'sass'; +import type { LegacyOptions } from 'sass/types/legacy/options'; + import * as d from './declarations'; -import * as path from 'path'; -import { LegacyAsyncImporter, LegacyImporterResult } from 'sass'; -import { LegacyOptions } from 'sass/types/legacy/options'; /** * Determine if the Sass plugin should be applied, based on the provided `fileName`