diff --git a/package-lock.json b/package-lock.json index b2173a7..1318fc2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1553,6 +1553,25 @@ } } }, + "downlevel-dts": { + "version": "0.10.0", + "resolved": "https://registry.npmjs.org/downlevel-dts/-/downlevel-dts-0.10.0.tgz", + "integrity": "sha512-AZ7tnUy4XJArsjv6Bcuivvxx+weMvOGHF6seu7e7PVOqMDHMSlfgMl1kt+F4Y2+5TmDwKWHOdimM1DZKihQs8Q==", + "dev": true, + "requires": { + "semver": "^7.3.2", + "shelljs": "^0.8.3", + "typescript": "^4.8.0-dev.20220719" + }, + "dependencies": { + "typescript": { + "version": "4.8.0-dev.20220719", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.8.0-dev.20220719.tgz", + "integrity": "sha512-IAZp6IDszN9iZi7R5LOqR5j0Ffy737RVQF7IefH1hNtFE+HiTjfsEYtWD2M0X/2feOCESZEKaa+GmuOVFuFhUQ==", + "dev": true + } + } + }, "eastasianwidth": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", @@ -2297,6 +2316,12 @@ "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==", "dev": true }, + "interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "dev": true + }, "irregular-plurals": { "version": "3.3.0", "resolved": "https://registry.npmjs.org/irregular-plurals/-/irregular-plurals-3.3.0.tgz", @@ -3410,6 +3435,15 @@ "picomatch": "^2.2.1" } }, + "rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha512-HFM8rkZ+i3zrV+4LQjwQ0W+ez98pApMGM3HUrN04j3CqzPOzl9nmP15Y8YXNm8QHGv/eacOVEjqhmWpkRV0NAw==", + "dev": true, + "requires": { + "resolve": "^1.1.6" + } + }, "regexpp": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/regexpp/-/regexpp-3.2.0.tgz", @@ -3645,6 +3679,17 @@ "integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==", "dev": true }, + "shelljs": { + "version": "0.8.5", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.5.tgz", + "integrity": "sha512-TiwcRcrkhHvbrZbnRcFYMLl30Dfov3HKqzp5tO5b4pt6G/SezKcYhmDg15zXVBswHmctSAQKznqNW2LO5tTDow==", + "dev": true, + "requires": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + } + }, "signal-exit": { "version": "3.0.6", "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.6.tgz", diff --git a/package.json b/package.json index 62cd905..a209c05 100644 --- a/package.json +++ b/package.json @@ -4,9 +4,18 @@ "description": "Rollup Sass files.", "main": "dist/index.js", "typings": "dist/index.d.ts", + "typesVersions": { + "<4.0": { + "*": [ + "ts3.5/*" + ] + } + }, "scripts": { "prepare": "npm run build && npm test", - "build": "tsc --project tsconfig.json", + "build": "npm run build-downlevel-dts && tsc --project tsconfig.json", + "build-downlevel-dts": "node scripts/clean-and-run-downlevel-dts.js", + "downlevel-dts": "downlevel-dts . ts3.5 [--to=3.5]", "test": "nyc --reporter=html --reporter=text ava ./test/*.test.ts -s && npm run test:rollup.config.spec.ts", "coverage": "nyc report --reporter=text-lcov | coveralls", "test:rollup.config.spec.ts": "tsc --project tsconfig.spec.json --noEmit" @@ -59,6 +68,7 @@ "@types/sass": "^1.16.1", "ava": "^4.3.1", "coveralls": "^3.1.1", + "downlevel-dts": "^0.10.0", "eslint": "^7.32.0", "jsdom": "^17.0.0", "nyc": "^15.1.0", diff --git a/scripts/clean-and-run-downlevel-dts.js b/scripts/clean-and-run-downlevel-dts.js new file mode 100644 index 0000000..9bd9b93 --- /dev/null +++ b/scripts/clean-and-run-downlevel-dts.js @@ -0,0 +1,47 @@ +/** + * @script clean-and-run-downlevel-dts.js + * @description Removes '{repo-root}/ts3.5' directory, re-creates it, runs + * `npm run downlevel-dts` from repo-root, and copies the root tsconfig.json file into new directory. + */ + const fs = require('fs').promises, + path = require('path'), + {spawn} = require('child_process'), + + {log, warn, error} = console, + + rootDir = path.join(__dirname, '..'), + outputDir = path.resolve(path.join(__dirname, '../ts3.5')), + + tsConfigFilePath = path.join(rootDir, 'tsconfig.json'), + tsConfigOutFilePath = path.join(outputDir, 'tsconfig.json'); + +(async () => + fs.rmdir(outputDir, {recursive: true}) + + .then(() => fs.mkdir(outputDir)) + + .then(() => fs.copyFile(tsConfigFilePath, tsConfigOutFilePath)) + + // Run downlevel-dts + .then(() => new Promise((resolve, reject) => { + + // Start downlevel-dts package script + const subProcess = spawn('npm', ['run', 'downlevel-dts'], {cwd: rootDir}); + + // Log child process buffer data as `string` + subProcess.stdout.on('data', data => log(data.toString().trim() + '\n')); + + // Log stderr, child process, buffer data as a `string` + subProcess.stderr.on('data', data => warn(data.toString().trim() + '\n')); + + // Handle process end + subProcess.on('close', (code) => code !== 0 ? + reject(`Child process existed with code ${code}.\n`) : + resolve('Process completed successfully.\n') + ); + + // Catch process start errors + subProcess.on('error', reject); + })) + +)().then(log, error);