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

remove ts, fixed cjs syntax

master
yutent 2023-06-18 22:24:16 +08:00
parent 2ef4d630d2
commit d0a6dd21f1
13 changed files with 90 additions and 588 deletions

View File

@ -1,406 +0,0 @@
'use strict'
var resolve = require('resolve')
var path = require('path')
var testFolder = path.relative(
process.cwd(),
path.dirname(resolve.sync('@less/test-data'))
)
var lessFolder = path.join(testFolder, 'less')
module.exports = function (grunt) {
grunt.option('stack', true)
// Report the elapsed execution time of tasks.
require('time-grunt')(grunt)
var git = require('git-rev')
// Sauce Labs browser
var browsers = [
// Desktop browsers
{
browserName: 'chrome',
version: 'latest',
platform: 'Windows 7'
},
{
browserName: 'firefox',
version: 'latest',
platform: 'Linux'
},
{
browserName: 'safari',
version: '9',
platform: 'OS X 10.11'
},
{
browserName: 'internet explorer',
version: '8',
platform: 'Windows XP'
},
{
browserName: 'internet explorer',
version: '11',
platform: 'Windows 8.1'
},
{
browserName: 'edge',
version: '13',
platform: 'Windows 10'
},
// Mobile browsers
{
browserName: 'ipad',
deviceName: 'iPad Air Simulator',
deviceOrientation: 'portrait',
version: '8.4',
platform: 'OS X 10.9'
},
{
browserName: 'iphone',
deviceName: 'iPhone 5 Simulator',
deviceOrientation: 'portrait',
version: '9.3',
platform: 'OS X 10.11'
},
{
browserName: 'android',
deviceName: 'Google Nexus 7 HD Emulator',
deviceOrientation: 'portrait',
version: '4.4',
platform: 'Linux'
}
]
var sauceJobs = {}
var browserTests = [
'filemanager-plugin',
'visitor-plugin',
'global-vars',
'modify-vars',
'production',
'rootpath-relative',
'rootpath-rewrite-urls',
'rootpath',
'relative-urls',
'rewrite-urls',
'browser',
'no-js-errors',
'legacy'
]
function makeJob(testName) {
sauceJobs[testName] = {
options: {
urls:
testName === 'all'
? browserTests.map(function (name) {
return (
'http://localhost:8081/tmp/browser/test-runner-' +
name +
'.html'
)
})
: [
'http://localhost:8081/tmp/browser/test-runner-' +
testName +
'.html'
],
testname: testName === 'all' ? 'Unit Tests for Less.js' : testName,
browsers: browsers,
public: 'public',
recordVideo: false,
videoUploadOnPass: false,
recordScreenshots: process.env.TRAVIS_BRANCH !== 'master',
build:
process.env.TRAVIS_BRANCH === 'master'
? process.env.TRAVIS_JOB_ID
: undefined,
tags: [
process.env.TRAVIS_BUILD_NUMBER,
process.env.TRAVIS_PULL_REQUEST,
process.env.TRAVIS_BRANCH
],
statusCheckAttempts: -1,
sauceConfig: {
'idle-timeout': 100
},
throttled: 5,
onTestComplete: function (result, callback) {
// Called after a unit test is done, per page, per browser
// 'result' param is the object returned by the test framework's reporter
// 'callback' is a Node.js style callback function. You must invoke it after you
// finish your work.
// Pass a non-null value as the callback's first parameter if you want to throw an
// exception. If your function is synchronous you can also throw exceptions
// directly.
// Passing true or false as the callback's second parameter passes or fails the
// test. Passing undefined does not alter the test result. Please note that this
// only affects the grunt task's result. You have to explicitly update the Sauce
// Labs job's status via its REST API, if you want so.
// This should be the encrypted value in Travis
var user = process.env.SAUCE_USERNAME
var pass = process.env.SAUCE_ACCESS_KEY
git.short(function (hash) {
require('phin')(
{
method: 'PUT',
url: [
'https://saucelabs.com/rest/v1',
user,
'jobs',
result.job_id
].join('/'),
auth: { user: user, pass: pass },
data: {
passed: result.passed,
build: 'build-' + hash
}
},
function (error, response) {
if (error) {
console.log(error)
callback(error)
} else if (response.statusCode !== 200) {
console.log(response)
callback(new Error('Unexpected response status'))
} else {
callback(null, result.passed)
}
}
)
})
}
}
}
}
// Make the SauceLabs jobs
;['all'].concat(browserTests).map(makeJob)
var path = require('path')
// Handle async / await in Rollup build for tests
const tsNodeRuntime = path.resolve(
path.join('node_modules', '.bin', 'ts-node')
)
const crossEnv = path.resolve(path.join('node_modules', '.bin', 'cross-env'))
// Project configuration.
grunt.initConfig({
shell: {
options: {
stdout: true,
failOnError: true,
execOptions: {
maxBuffer: Infinity
}
},
build: {
command: [
/** Browser runtime */
'node build/rollup.js --dist',
/** Copy to repo root */
'npm run copy:root',
/** Node.js runtime */
'npm run build'
].join(' && ')
},
testbuild: {
command: [
'npm run build',
'node build/rollup.js --browser --out=./tmp/browser/less.min.js'
].join(' && ')
},
testcjs: {
command: 'npm run build'
},
testbrowser: {
command:
'node build/rollup.js --browser --out=./tmp/browser/less.min.js'
},
test: {
command: [
// https://github.com/TypeStrong/ts-node/issues/693#issuecomment-848907036
crossEnv + ' TS_NODE_SCOPE=true',
tsNodeRuntime + ' test/test-es6.ts',
'node test/index.js'
].join(' && ')
},
generatebrowser: {
command: 'node test/browser/generator/generate.js'
},
runbrowser: {
command: 'node test/browser/generator/runner.js'
},
benchmark: {
command: 'node benchmark/index.js'
},
opts: {
// test running with all current options (using `opts` since `options` means something already)
command: [
// @TODO: make this more thorough
// CURRENT OPTIONS
`node bin/lessc --ie-compat ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
// --math
`node bin/lessc --math=always ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens-division ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict-legacy ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
// DEPRECATED OPTIONS
// --strict-math
`node bin/lessc --strict-math=on ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`
].join(' && ')
},
plugin: {
command: [
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
'cd lib',
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/_main/lazy-eval.less ../tmp/lazy-eval.css`,
'cd ..',
// Test multiple plugins
`node bin/lessc --plugin=clean-css="--s1 --advanced" --plugin=autoprefix="ie 11,Edge >= 13,Chrome >= 47,Firefox >= 45,iOS >= 9.2,Safari >= 9" ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`
].join(' && ')
},
'sourcemap-test': {
// quoted value doesn't seem to get picked up by time-grunt, or isn't output, at least; maybe just "sourcemap" is fine?
command: [
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/_main/import.less test/sourcemaps/import.css`,
`node bin/lessc --source-map ${lessFolder}/sourcemaps/basic.less test/sourcemaps/basic.css`
].join(' && ')
}
},
eslint: {
target: [
'test/**/*.js',
'src/less*/**/*.js',
'!test/less/errors/plugin/plugin-error.js'
],
options: {
configFile: '.eslintrc.js',
fix: true
}
},
connect: {
server: {
options: {
port: 8081
}
}
},
'saucelabs-mocha': sauceJobs,
// Clean the version of less built for the tests
clean: {
test: ['test/browser/less.js', 'tmp', 'test/less-bom'],
'sourcemap-test': ['test/sourcemaps/*.css', 'test/sourcemaps/*.map'],
sauce_log: ['sc_*.log']
}
})
// Load these plugins to provide the necessary tasks
grunt.loadNpmTasks('grunt-saucelabs')
require('jit-grunt')(grunt)
// by default, run tests
grunt.registerTask('default', ['test'])
// Release
grunt.registerTask('dist', ['shell:build'])
// Create the browser version of less.js
grunt.registerTask('browsertest-lessjs', ['shell:testbrowser'])
// Run all browser tests
grunt.registerTask('browsertest', [
'browsertest-lessjs',
'connect',
'shell:runbrowser'
])
// setup a web server to run the browser tests in a browser rather than phantom
grunt.registerTask('browsertest-server', [
'browsertest-lessjs',
'shell:generatebrowser',
'connect::keepalive'
])
var previous_force_state = grunt.option('force')
grunt.registerTask('force', function (set) {
if (set === 'on') {
grunt.option('force', true)
} else if (set === 'off') {
grunt.option('force', false)
} else if (set === 'restore') {
grunt.option('force', previous_force_state)
}
})
grunt.registerTask('sauce', [
'browsertest-lessjs',
'shell:generatebrowser',
'connect',
'sauce-after-setup'
])
grunt.registerTask('sauce-after-setup', [
'saucelabs-mocha:all',
'clean:sauce_log'
])
var testTasks = [
'clean',
'eslint',
'shell:testbuild',
'shell:test',
'shell:opts',
'shell:plugin',
'connect',
'shell:runbrowser'
]
if (
isNaN(Number(process.env.TRAVIS_PULL_REQUEST, 10)) &&
process.env.TRAVIS_BRANCH === 'master'
) {
testTasks.push('force:on')
testTasks.push('sauce-after-setup')
testTasks.push('force:off')
}
// Run all tests
grunt.registerTask('test', testTasks)
// Run shell option tests (includes deprecated options)
grunt.registerTask('shell-options', ['shell:opts'])
// Run shell plugin test
grunt.registerTask('shell-plugin', ['shell:plugin'])
// Quickly build and run Node tests
grunt.registerTask('quicktest', ['shell:testcjs', 'shell:test'])
// generate a good test environment for testing sourcemaps
grunt.registerTask('sourcemap-test', [
'clean:sourcemap-test',
'shell:build:lessc',
'shell:sourcemap-test',
'connect::keepalive'
])
// Run benchmark
grunt.registerTask('benchmark', ['shell:testcjs', 'shell:benchmark'])
}

View File

@ -1,6 +1,6 @@
const pkg = require('./../package.json')
import pkg from './../package.json' assert { type: 'json' }
module.exports = `/**
export default `/**
* Less - ${pkg.description} v${pkg.version}
* http://lesscss.org
*

View File

@ -1,15 +1,17 @@
const rollup = require('rollup')
const typescript = require('rollup-plugin-typescript2')
const commonjs = require('@rollup/plugin-commonjs')
const json = require('@rollup/plugin-json')
const resolve = require('@rollup/plugin-node-resolve').nodeResolve
const terser = require('rollup-plugin-terser').terser
const banner = require('./banner')
const path = require('path')
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, '..')
const args = require('minimist')(process.argv.slice(2))
import minimist from 'minimist'
const args = minimist(process.argv.slice(2))
let outDir = args.dist ? './dist' : './tmp'

View File

@ -1 +1 @@
module.exports = require('./lib/less-node').default;
export default './lib/less-node'

View File

@ -124,7 +124,6 @@
],
"dependencies": {
"copy-anything": "^2.0.1",
"parse-node-version": "^1.0.1",
"tslib": "^2.3.0"
"parse-node-version": "^1.0.1"
}
}

View File

@ -1,3 +1,6 @@
import mime from 'mime'
import SourceMap from 'source-map'
export default {
encodeBase64: function encodeBase64(str) {
// Avoid Buffer constructor on newer versions of Node.js.
@ -5,12 +8,12 @@ export default {
return buffer.toString('base64')
},
mimeLookup: function (filename) {
return require('mime').lookup(filename)
return mime.lookup(filename)
},
charsetLookup: function (mime) {
return require('mime').charsets.lookup(mime)
return mime.charsets.lookup(mime)
},
getSourceMapGenerator: function getSourceMapGenerator() {
return require('source-map').SourceMapGenerator
return SourceMap.SourceMapGenerator
}
}

View File

@ -1,7 +1,6 @@
let fs
try {
fs = require('graceful-fs')
} catch (e) {
fs = require('fs')
}
export default fs
export default fs from 'graceful-fs'
// export default fs from 'fs'

View File

@ -1,6 +1,7 @@
import Dimension from '../less/tree/dimension'
import Expression from '../less/tree/expression'
import functionRegistry from './../less/functions/function-registry'
import sizeOf from 'image-size'
export default environment => {
function imageSize(functionContext, filePathNode) {
@ -41,7 +42,6 @@ export default environment => {
throw fileSync.error
}
const sizeOf = require('image-size')
return sizeOf(fileSync.filename)
}

View File

@ -7,19 +7,23 @@ const less = createFromEnvironment(environment, [
new UrlFileManager()
])
import lesscHelper from './lessc-helper'
import PluginLoader from './plugin-loader'
import fs from './fs.js'
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 = require('./plugin-loader').default
less.fs = require('./fs').default
less.PluginLoader = PluginLoader
less.fs = fs
less.FileManager = FileManager
less.UrlFileManager = UrlFileManager
// Set up options
less.options = require('../less/default-options').default()
less.options = options
// provide image-size functionality
require('./image-size').default(less.environment)
imageSize(less.environment)
export default less

View File

@ -8,6 +8,7 @@ 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(), {
@ -19,7 +20,7 @@ UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
return new Promise((fulfill, reject) => {
if (request === undefined) {
try {
request = require('needle')
request = needle
} catch (e) {
request = null
}

View File

@ -1,70 +1,68 @@
// Export a new default each time
export default function () {
return {
/* Inline Javascript - @plugin still allowed */
javascriptEnabled: false,
export default {
/* Inline Javascript - @plugin still allowed */
javascriptEnabled: false,
/* Outputs a makefile import dependency list to stdout. */
depends: false,
/* Outputs a makefile import dependency list to stdout. */
depends: false,
/* (DEPRECATED) Compress using less built-in compression.
* This does an okay job but does not utilise all the tricks of
* dedicated css compression. */
compress: false,
/* (DEPRECATED) Compress using less built-in compression.
* This does an okay job but does not utilise all the tricks of
* dedicated css compression. */
compress: false,
/* Runs the less parser and just reports errors without any output. */
lint: false,
/* Runs the less parser and just reports errors without any output. */
lint: false,
/* Sets available include paths.
* If the file in an @import rule does not exist at that exact location,
* less will look for it at the location(s) passed to this option.
* You might use this for instance to specify a path to a library which
* you want to be referenced simply and relatively in the less files. */
paths: [],
/* Sets available include paths.
* If the file in an @import rule does not exist at that exact location,
* less will look for it at the location(s) passed to this option.
* You might use this for instance to specify a path to a library which
* you want to be referenced simply and relatively in the less files. */
paths: [],
/* color output in the terminal */
color: true,
/* color output in the terminal */
color: true,
/* The strictImports controls whether the compiler will allow an @import inside of either
* @media blocks or (a later addition) other selector blocks.
* See: https://github.com/less/less.js/issues/656 */
strictImports: false,
/* The strictImports controls whether the compiler will allow an @import inside of either
* @media blocks or (a later addition) other selector blocks.
* See: https://github.com/less/less.js/issues/656 */
strictImports: false,
/* Allow Imports from Insecure HTTPS Hosts */
insecure: false,
/* Allow Imports from Insecure HTTPS Hosts */
insecure: false,
/* Allows you to add a path to every generated import and url in your css.
* This does not affect less import statements that are processed, just ones
* that are left in the output css. */
rootpath: '',
/* Allows you to add a path to every generated import and url in your css.
* This does not affect less import statements that are processed, just ones
* that are left in the output css. */
rootpath: '',
/* By default URLs are kept as-is, so if you import a file in a sub-directory
* that references an image, exactly the same URL will be output in the css.
* This option allows you to re-write URL's in imported files so that the
* URL is always relative to the base imported file */
rewriteUrls: false,
/* By default URLs are kept as-is, so if you import a file in a sub-directory
* that references an image, exactly the same URL will be output in the css.
* This option allows you to re-write URL's in imported files so that the
* URL is always relative to the base imported file */
rewriteUrls: false,
/* How to process math
* 0 always - eagerly try to solve all operations
* 1 parens-division - require parens for division "/"
* 2 parens | strict - require parens for all operations
* 3 strict-legacy - legacy strict behavior (super-strict)
*/
math: 1,
/* How to process math
* 0 always - eagerly try to solve all operations
* 1 parens-division - require parens for division "/"
* 2 parens | strict - require parens for all operations
* 3 strict-legacy - legacy strict behavior (super-strict)
*/
math: 1,
/* Without this option, less attempts to guess at the output unit when it does maths. */
strictUnits: false,
/* Without this option, less attempts to guess at the output unit when it does maths. */
strictUnits: false,
/* Effectively the declaration is put at the top of your base Less file,
* meaning it can be used but it also can be overridden if this variable
* is defined in the file. */
globalVars: null,
/* Effectively the declaration is put at the top of your base Less file,
* meaning it can be used but it also can be overridden if this variable
* is defined in the file. */
globalVars: null,
/* As opposed to the global variable option, this puts the declaration at the
* end of your base file, meaning it will override anything defined in your Less file. */
modifyVars: null,
/* As opposed to the global variable option, this puts the declaration at the
* end of your base file, meaning it will override anything defined in your Less file. */
modifyVars: null,
/* This option allows you to specify a argument to go on to every URL. */
urlArgs: ''
}
/* This option allows you to specify a argument to go on to every URL. */
urlArgs: ''
}

View File

@ -1,21 +0,0 @@
export interface Environment {
/**
* Converts a string to a base 64 string
*/
encodeBase64(str: string): string
/**
* Lookup the mime-type of a filename
*/
mimeLookup(filename: string): string
/**
* Look up the charset of a mime type
* @param mime
*/
charsetLookup(mime: string): string
/**
* Gets a source map generator
*
* @todo - Figure out precise type
*/
getSourceMapGenerator(): any
}

View File

@ -1,77 +0,0 @@
import type { Environment } from './environment-api'
export interface FileManager {
/**
* Given the full path to a file, return the path component
* Provided by AbstractFileManager
*/
getPath(filename: string): string
/**
* Append a .less extension if appropriate. Only called if less thinks one could be added.
* Provided by AbstractFileManager
*/
tryAppendLessExtension(filename: string): string
/**
* Whether the rootpath should be converted to be absolute.
* The browser ovverides this to return true because urls must be absolute.
* Provided by AbstractFileManager (returns false)
*/
alwaysMakePathsAbsolute(): boolean
/**
* Returns whether a path is absolute
* Provided by AbstractFileManager
*/
isPathAbsolute(path: string): boolean
/**
* joins together 2 paths
* Provided by AbstractFileManager
*/
join(basePath: string, laterPath: string): string
/**
* Returns the difference between 2 paths
* E.g. url = a/ baseUrl = a/b/ returns ../
* url = a/b/ baseUrl = a/ returns b/
* Provided by AbstractFileManager
*/
pathDiff(url: string, baseUrl: string): string
/**
* Returns whether this file manager supports this file for syncronous file retrieval
* If true is returned, loadFileSync will then be called with the file.
* Provided by AbstractFileManager (returns false)
*
* @todo - Narrow Options type
*/
supportsSync(
filename: string,
currentDirectory: string,
options: Record<string, any>,
environment: Environment
): boolean
/**
* If file manager supports async file retrieval for this file type
*/
supports(
filename: string,
currentDirectory: string,
options: Record<string, any>,
environment: Environment
): boolean
/**
* Loads a file asynchronously.
*/
loadFile(
filename: string,
currentDirectory: string,
options: Record<string, any>,
environment: Environment
): Promise<{ filename: string, contents: string }>
/**
* Loads a file synchronously. Expects an immediate return with an object
*/
loadFileSync(
filename: string,
currentDirectory: string,
options: Record<string, any>,
environment: Environment
): { error?: unknown, filename: string, contents: string }
}