This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
less
Archived
1
0
Fork 0

完成less的修改

master
yutent 2023-06-19 19:10:44 +08:00
parent d0a6dd21f1
commit 6e3b874108
14 changed files with 220 additions and 419 deletions

3
.gitignore vendored
View File

@ -1,8 +1,7 @@
.vscode
node_modules/
dist
benchmark
bin
test
*.sublime-project
*.sublime-workspace

12
build.js Normal file
View File

@ -0,0 +1,12 @@
import Es from 'esbuild'
import fs from 'iofs'
Es.buildSync({
entryPoints: ['src/less-node/index.js'],
outdir: 'dist',
platform: 'node',
format: 'esm',
// minify: true,
bundle: true,
target: 'node12'
})

View File

@ -1,14 +0,0 @@
import pkg from './../package.json' assert { type: 'json' }
export default `/**
* Less - ${pkg.description} v${pkg.version}
* http://lesscss.org
*
* Copyright (c) 2009-${new Date().getFullYear()}, ${pkg.author.name} <${
pkg.author.email
}>
* Licensed under the ${pkg.license} License.
*
* @license ${pkg.license}
*/
`

View File

@ -1,90 +0,0 @@
import rollup from 'rollup'
import typescript from 'rollup-plugin-typescript2'
import commonjs from '@rollup/plugin-commonjs'
import json from '@rollup/plugin-json'
import resolve from '@rollup/plugin-node-resolve'
import terser from 'rollup-plugin-terser'
import banner from './banner'
import path from 'path')
const rootPath = path.join(__dirname, '..')
import minimist from 'minimist'
const args = minimist(process.argv.slice(2))
let outDir = args.dist ? './dist' : './tmp'
async function buildBrowser() {
let bundle = await rollup.rollup({
input: './src/less-browser/bootstrap.js',
output: [
{
file: 'less.js',
format: 'umd'
},
{
file: 'less.min.js',
format: 'umd'
}
],
plugins: [
resolve(),
commonjs(),
json(),
typescript({
verbosity: 2,
tsconfigDefaults: {
compilerOptions: {
allowJs: true,
sourceMap: true,
target: 'ES5'
}
},
include: ['*.ts', '**/*.ts', '*.js', '**/*.js'],
exclude: ['node_modules'] // only transpile our source code
}),
terser({
compress: true,
include: [/^.+\.min\.js$/],
output: {
comments: function (node, comment) {
if (comment.type == 'comment2') {
// preserve banner
return /@license/i.test(comment.value)
}
}
}
})
]
})
if (!args.out || args.out.indexOf('less.js') > -1) {
const file = args.out || `${outDir}/less.js`
console.log(`Writing ${file}...`)
await bundle.write({
file: path.join(rootPath, file),
format: 'umd',
name: 'less',
banner
})
}
if (!args.out || args.out.indexOf('less.min.js') > -1) {
const file = args.out || `${outDir}/less.min.js`
console.log(`Writing ${file}...`)
await bundle.write({
file: path.join(rootPath, file),
format: 'umd',
name: 'less',
sourcemap: true,
banner
})
}
}
async function build() {
await buildBrowser()
}
build()

View File

@ -1 +0,0 @@
export default './lib/less-node'

View File

@ -1,101 +1,24 @@
{
"name": "less",
"version": "4.1.3",
"description": "Leaner CSS",
"name": "@bytedo/less",
"version": "0.0.1",
"type": "module",
"description": "less精简版",
"homepage": "http://lesscss.org",
"author": {
"name": "Alexis Sellier",
"email": "self@cloudhead.net"
},
"author": "yutent",
"contributors": [
"The Core Less Team"
],
"repository": {
"type": "git",
"url": "https://github.com/less/less.js.git"
"url": "https://github.com/bytedo/less.git"
},
"license": "Apache-2.0",
"bin": {
"lessc": "./bin/lessc"
},
"main": "index",
"module": "./lib/less-node/index",
"directories": {
"test": "./test"
},
"browser": "./dist/less.js",
"engines": {
"node": ">=6"
},
"main": "dist/index.js",
"files": [
"dist/*"
],
"scripts": {
"test": "grunt test",
"grunt": "grunt",
"lint": "eslint '**/*.{ts,js}'",
"lint:fix": "eslint '**/*.{ts,js}' --fix",
"build": "npm-run-all clean compile",
"clean": "shx rm -rf ./lib tsconfig.tsbuildinfo",
"compile": "tsc -p tsconfig.build.json",
"copy:root": "shx cp -rf ./dist ../../",
"dev": "tsc -p tsconfig.build.json -w",
"prepublishOnly": "grunt dist"
},
"optionalDependencies": {
"errno": "^0.1.1",
"graceful-fs": "^4.1.2",
"image-size": "~0.5.0",
"make-dir": "^2.1.0",
"mime": "^1.4.1",
"needle": "^3.1.0",
"source-map": "~0.6.0"
},
"devDependencies": {
"@less/test-data": "^4.1.0",
"@less/test-import-module": "^4.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-json": "^4.1.0",
"@rollup/plugin-node-resolve": "^11.0.0",
"@typescript-eslint/eslint-plugin": "^4.28.0",
"@typescript-eslint/parser": "^4.28.0",
"benny": "^3.6.12",
"bootstrap-less-port": "0.3.0",
"chai": "^4.2.0",
"cross-env": "^7.0.3",
"diff": "^3.2.0",
"eslint": "^7.29.0",
"fs-extra": "^8.1.0",
"git-rev": "^0.2.1",
"globby": "^10.0.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
"grunt-contrib-clean": "^1.0.0",
"grunt-contrib-connect": "^1.0.2",
"grunt-eslint": "^23.0.0",
"grunt-saucelabs": "^9.0.1",
"grunt-shell": "^1.3.0",
"html-template-tag": "^3.2.0",
"jit-grunt": "^0.10.0",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.5.1",
"minimist": "^1.2.0",
"mocha": "^6.2.1",
"mocha-headless-chrome": "^4.0.0",
"mocha-teamcity-reporter": "^3.0.0",
"nock": "^11.8.2",
"npm-run-all": "^4.1.5",
"performance-now": "^0.2.0",
"phin": "^2.2.3",
"promise": "^7.1.1",
"read-glob": "^3.0.0",
"resolve": "^1.17.0",
"rollup": "^2.52.2",
"rollup-plugin-terser": "^5.1.1",
"rollup-plugin-typescript2": "^0.29.0",
"semver": "^6.3.0",
"shx": "^0.3.2",
"time-grunt": "^1.3.0",
"ts-node": "^9.1.1",
"typescript": "^4.3.4",
"uikit": "2.27.4"
"build": "node build.js"
},
"keywords": [
"compile less",
@ -121,9 +44,5 @@
"stylesheet",
"variables in css",
"css less"
],
"dependencies": {
"copy-anything": "^2.0.1",
"parse-node-version": "^1.0.1"
}
]
}

View File

@ -1,16 +1,15 @@
import path from 'path'
import fs from './fs'
import fs from 'fs'
import AbstractFileManager from '../less/environment/abstract-file-manager.js'
const FileManager = function () {}
FileManager.prototype = Object.assign(new AbstractFileManager(), {
export default class FileManager extends AbstractFileManager {
supports() {
return true
},
}
supportsSync() {
return true
},
}
loadFile(filename, currentDirectory, options, environment, callback) {
let fullFilename
@ -142,12 +141,10 @@ FileManager.prototype = Object.assign(new AbstractFileManager(), {
}
})(0)
}
},
}
loadFileSync(filename, currentDirectory, options, environment) {
options.syncImport = true
return this.loadFile(filename, currentDirectory, options, environment)
}
})
export default FileManager
}

View File

@ -1,6 +0,0 @@
export default fs from 'graceful-fs'
// export default fs from 'fs'

View File

@ -1,20 +1,17 @@
import environment from './environment'
// import environment from './environment'
import FileManager from './file-manager'
import UrlFileManager from './url-file-manager'
import createFromEnvironment from '../less'
const less = createFromEnvironment(environment, [
const less = createFromEnvironment({}, [
new FileManager(),
new UrlFileManager()
])
import lesscHelper from './lessc-helper'
import PluginLoader from './plugin-loader'
import fs from './fs.js'
import fs from 'fs'
import options from '../less/default-options'
import imageSize from './image-size'
// allow people to create less with their own environment
less.createFromEnvironment = createFromEnvironment
less.lesscHelper = lesscHelper
less.PluginLoader = PluginLoader
less.fs = fs
less.FileManager = FileManager
@ -23,7 +20,4 @@ less.UrlFileManager = UrlFileManager
// Set up options
less.options = options
// provide image-size functionality
imageSize(less.environment)
export default less

View File

@ -1,9 +1,8 @@
// lessc_helper.js
//
// helper functions for lessc
const lessc_helper = {
// Stylize a string
stylize: function (str, style) {
export function stylize(str, style) {
const styles = {
reset: [0, 0],
bold: [1, 22],
@ -15,10 +14,10 @@ const lessc_helper = {
grey: [90, 39]
}
return `\x1b[${styles[style][0]}m${str}\x1b[${styles[style][1]}m`
},
}
// Print command line options
printUsage: function () {
export function printUsage() {
console.log(
'usage: lessc [option option=parameter ...] <source> [destination]'
)
@ -52,9 +51,7 @@ const lessc_helper = {
console.log(
' --insecure Allows imports from insecure https hosts.'
)
console.log(
' -v, --version Prints version number and exit.'
)
console.log(' -v, --version Prints version number and exit.')
console.log(' --verbose Be verbose.')
console.log(
' --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map).'
@ -137,9 +134,7 @@ const lessc_helper = {
console.log(' --disable-plugin-rule Disallow @plugin statements')
console.log('')
console.log('-------------------------- Deprecated ----------------')
console.log(
' -sm=on|off Legacy parens-only math. Use --math'
)
console.log(' -sm=on|off Legacy parens-only math. Use --math')
console.log(' --strict-math=on|off ')
console.log('')
console.log(' --line-numbers=TYPE Outputs filename and line numbers.')
@ -168,12 +163,3 @@ const lessc_helper = {
console.log('Report bugs to: http://github.com/less/less.js/issues')
console.log('Home page: <http://lesscss.org/>')
}
}
// Exports helper functions
// eslint-disable-next-line no-prototype-builtins
for (const h in lessc_helper) {
if (lessc_helper.hasOwnProperty(h)) {
exports[h] = lessc_helper[h]
}
}

View File

@ -8,7 +8,6 @@ import url from 'url'
let request
import AbstractFileManager from '../less/environment/abstract-file-manager.js'
import logger from '../less/logger'
import needle from 'needle'
const UrlFileManager = function () {}
UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
@ -18,13 +17,6 @@ UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
loadFile(filename, currentDirectory, options, environment) {
return new Promise((fulfill, reject) => {
if (request === undefined) {
try {
request = needle
} catch (e) {
request = null
}
}
if (!request) {
reject({
type: 'File',

View File

@ -19,7 +19,6 @@ import ImportManager from './import-manager'
import Parse from './parse'
import Render from './render'
import { version } from '../../package.json'
import parseVersion from 'parse-node-version'
export default function (environment, fileManagers) {
let sourceMapOutput, sourceMapBuilder, parseTree, importManager
@ -33,9 +32,9 @@ export default function (environment, fileManagers) {
const render = Render(environment, parseTree, importManager)
const parse = Parse(environment, parseTree, importManager)
const v = parseVersion(`v${version}`)
const v = version.split('.').map(n => +n)
const initial = {
version: [v.major, v.minor, v.patch],
version: [v[0], v[1], v[2]],
data,
tree,
Environment,

View File

@ -145,7 +145,7 @@ const Parser = function Parser(context, imports, fileInfo, currentIndex) {
// @param callback call `callback` when done.
// @param [additionalData] An optional map which can contains vars - a map (key, value) of variables to apply
//
parse: function (str, callback, additionalData) {
parse(str, callback, additionalData) {
let root
let err = null
let globalVars

View File

@ -1,6 +1,27 @@
/* jshint proto: true */
import * as Constants from './constants'
import { copy } from 'copy-anything'
function copy(obj = {}) {
if (Array.isArray(obj)) {
return obj.map(it => copy(it))
} else if (typeof obj === 'object') {
let tmp = {}
for (let k in obj) {
if (obj[k] === void 0) {
continue
} else {
if (typeof obj[k] === 'object' && obj[k] !== null) {
tmp[k] = copy(obj[k])
} else {
tmp[k] = obj[k]
}
}
}
return tmp
} else {
return obj
}
}
export function getLocation(index, inputStream) {
let n = index + 1
@ -22,14 +43,7 @@ export function getLocation(index, inputStream) {
}
export function copyArray(arr) {
let i
const length = arr.length
const copy = new Array(length)
for (i = 0; i < length; i++) {
copy[i] = arr[i]
}
return copy
return [...arr]
}
export function clone(obj) {
@ -46,10 +60,10 @@ export function defaults(obj1, obj2) {
let newObj = obj2 || {}
if (!obj2._defaults) {
newObj = {}
const defaults = copy(obj1)
newObj._defaults = defaults
const _defaults = copy(obj1)
newObj._defaults = _defaults
const cloned = obj2 ? copy(obj2) : {}
Object.assign(newObj, defaults, cloned)
Object.assign(newObj, _defaults, cloned)
}
return newObj
}