From ab4486442c313b05bde991a800ee070e51547623 Mon Sep 17 00:00:00 2001 From: yutent Date: Tue, 21 Feb 2023 16:38:26 +0800 Subject: [PATCH] 1.58.3 --- .gitignore | 16 ++++++++++++ package.json | 33 +++++++++++++++++++++++++ readme.md | 17 +++++++++++++ update.mjs | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100644 .gitignore create mode 100644 package.json create mode 100644 readme.md create mode 100644 update.mjs diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdda635 --- /dev/null +++ b/.gitignore @@ -0,0 +1,16 @@ +.vscode +node_modules/ +src/ +dist/ + +*.sublime-project +*.sublime-workspace +package-lock.json + +._* + +.Spotlight-V100 +.Trashes +.DS_Store +.AppleDouble +.LSOverride \ No newline at end of file diff --git a/package.json b/package.json new file mode 100644 index 0000000..5c49849 --- /dev/null +++ b/package.json @@ -0,0 +1,33 @@ +{ + "name": "@bytedo/sass", + "version": "1.58.3", + "description": "sass的精简版", + "author": "yutent ", + "main": "dist/index.js", + "files": [ + "dist/*" + ], + "scripts": { + "build": "node ./update.js" + }, + "keywords": [ + "sass", + "scss", + "node-sass", + "node-scss" + ], + "repository": { + "type": "git", + "url": "https://github.com/bytedo/sass.git" + }, + "dependencies": { + "immutable": "^4.0.0" + }, + "devDependencies": { + "esbuild": "^0.17.8", + "iofs": "^1.5.3" + }, + "engines": { + "node": ">=12.0.0" + } +} \ No newline at end of file diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..5094a11 --- /dev/null +++ b/readme.md @@ -0,0 +1,17 @@ +## sass +> [`sass`](https://www.npmjs.com/package/sass)的精简版。 + + +### 说明 + +- 本包并未修改逻辑代码。 +- 移除了`chokidar`和`source-map-js`2个包, 移除了作为命令行运行的配置。 + + +### 出现背景 +> 纯js环境运行, 出于代码体积要求, 尽量缩减不必要的依赖。 + + +### 使用文档 + +请到 [`sass`](https://www.npmjs.com/package/sass) 查看。 \ No newline at end of file diff --git a/update.mjs b/update.mjs new file mode 100644 index 0000000..0edc187 --- /dev/null +++ b/update.mjs @@ -0,0 +1,70 @@ +/** + * {} + * @author yutent + * @date 2023/02/15 22:46:25 + */ + +import Es from 'esbuild' +import fs from 'iofs' +import { resolve } from 'path' +import { exec } from 'child_process' +import pkg from './package.json' assert { type: 'json' } + +const NPM_URL = 'https://registry.npmmirror.com' +const PKG_NAME = 'sass' + +function download(url) { + return fetch(url).then(r => r.arrayBuffer()) +} + +export function execAsync(cmd) { + return new Promise((yes, no) => { + exec(cmd, { cwd: resolve('./') }, (err, res) => { + if (err) { + no(err) + } else { + yes(res) + } + }) + }) +} + +!(async function () { + let { version, url } = await fetch( + 'https://registry.npmmirror.com/' + PKG_NAME, + { + headers: { + 'content-type': 'application/json', + accept: 'application/json' + } + } + ) + .then(r => r.json()) + .then(r => { + let v = r['dist-tags'].latest + let url = r.versions[v].dist.tarball + return { version: v, url } + }) + let ab = await download(url) + + pkg.version = version + + fs.echo(JSON.stringify(pkg, null, 2), './package.json') + fs.echo(Buffer.from(ab), `./${PKG_NAME}.tgz`) + + await execAsync(`tar -xzf ${PKG_NAME}.tgz`) + + Es.buildSync({ + entryPoints: ['package/sass.default.dart.js', 'package/sass.dart.js'], + outdir: 'dist', + platform: 'node', + minify: true, + bundle: false, + target: 'node12' + }) + + fs.mv('dist/sass.default.dart.js', 'src/index.js') + + fs.rm('./package', true) + fs.rm(`./${PKG_NAME}.tgz`) +})()