Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@
node_modules
!package-lock.json
npm-debug.log

# Coverage
.nyc_output
coverage
*.lcov
33 changes: 16 additions & 17 deletions packages/less/Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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');
var lessFolder = testFolder;

module.exports = function(grunt) {
grunt.option("stack", true);
Expand Down Expand Up @@ -85,8 +85,7 @@ module.exports = function(grunt) {
"relative-urls",
"rewrite-urls",
"browser",
"no-js-errors",
"legacy"
"no-js-errors"
];

function makeJob(testName) {
Expand Down Expand Up @@ -214,7 +213,7 @@ module.exports = function(grunt) {
command: "node build/rollup.js --browser --out=./tmp/browser/less.min.js"
},
test: {
command: 'ts-node test/test-es6.ts && node test/index.js'
command: 'npx ts-node test/test-es6.ts && node test/index.js'
},
generatebrowser: {
command: 'node test/browser/generator/generate.js'
Expand All @@ -230,35 +229,35 @@ module.exports = function(grunt) {
command: [
// @TODO: make this more thorough
// CURRENT OPTIONS
`node bin/lessc --ie-compat ${lessFolder}/_main/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --ie-compat ${lessFolder}/tests-unit/lazy-eval/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`,
`node bin/lessc --math=always ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens-division ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=parens ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict ${lessFolder}/tests-unit/lazy-eval/lazy-eval.less tmp/lazy-eval.css`,
`node bin/lessc --math=strict-legacy ${lessFolder}/tests-unit/lazy-eval/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`
`node bin/lessc --strict-math=on ${lessFolder}/tests-unit/lazy-eval/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`,
`node bin/lessc --clean-css="--s1 --advanced" ${lessFolder}/tests-unit/lazy-eval/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`,
`node ../bin/lessc --clean-css="--s1 --advanced" ../${lessFolder}/tests-unit/lazy-eval/lazy-eval.less ../tmp/lazy-eval.css`,
`node ../bin/lessc --source-map=lazy-eval.css.map --autoprefix ../${lessFolder}/tests-unit/lazy-eval/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`
`node bin/lessc --plugin=clean-css="--s1 --advanced" --plugin=autoprefix="ie 11,Edge >= 13,Chrome >= 47,Firefox >= 45,iOS >= 9.2,Safari >= 9" ${lessFolder}/tests-unit/lazy-eval/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`
`node bin/lessc --source-map=test/sourcemaps/maps/import-map.map ${lessFolder}/tests-unit/import/import.less test/sourcemaps/import.css`,
`node bin/lessc --source-map ${lessFolder}/tests-config/sourcemaps/basic.less test/sourcemaps/basic.css`
].join(" && ")
}
},
Expand Down
75 changes: 35 additions & 40 deletions packages/less/bin/lessc
Original file line number Diff line number Diff line change
Expand Up @@ -98,53 +98,48 @@ function render() {
}

if (options.sourceMap) {
sourceMapOptions.sourceMapInputFilename = input;

if (!sourceMapOptions.sourceMapFullFilename) {
if (!output && !sourceMapFileInline) {
console.error('the sourcemap option only has an optional filename if the css filename is given');
console.error('consider adding --source-map-map-inline which embeds the sourcemap into the css');
process.exitCode = 1;
return;
} // its in the same directory, so always just the basename


if (output) {
sourceMapOptions.sourceMapOutputFilename = path.basename(output);
sourceMapOptions.sourceMapFullFilename = ''.concat(output, '.map');
} // its in the same directory, so always just the basename


if ('sourceMapFullFilename' in sourceMapOptions) {
sourceMapOptions.sourceMapFilename = path.basename(sourceMapOptions.sourceMapFullFilename);
}
} else if (options.sourceMap && !sourceMapFileInline) {
var mapFilename = path.resolve(process.cwd(), sourceMapOptions.sourceMapFullFilename);
var mapDir = path.dirname(mapFilename);
var outputDir = path.dirname(output); // find the path from the map to the output file

// eslint-disable-next-line max-len
sourceMapOptions.sourceMapOutputFilename = path.join(path.relative(mapDir, outputDir), path.basename(output)); // make the sourcemap filename point to the sourcemap relative to the css file output directory

sourceMapOptions.sourceMapFilename = path.join(path.relative(outputDir, mapDir), path.basename(sourceMapOptions.sourceMapFullFilename));
}

// Validate conflicting options
if (sourceMapOptions.sourceMapURL && sourceMapOptions.disableSourcemapAnnotation) {
console.error('You cannot provide flag --source-map-url with --source-map-no-annotation.');
console.error('Please remove one of those flags.');
process.exitcode = 1;
return;
}
}

if (sourceMapOptions.sourceMapBasepath === undefined) {
sourceMapOptions.sourceMapBasepath = input ? path.dirname(input) : process.cwd();
}

if (sourceMapOptions.sourceMapRootpath === undefined) {
var pathToMap = path.dirname((sourceMapFileInline ? output : sourceMapOptions.sourceMapFullFilename) || '.');
var pathToInput = path.dirname(sourceMapOptions.sourceMapInputFilename || '.');
sourceMapOptions.sourceMapRootpath = path.relative(pathToMap, pathToInput);
// Handle explicit sourceMapFullFilename (from --source-map=filename)
// Normalization of other options (sourceMapBasepath, sourceMapRootpath, etc.)
// is handled automatically in parse-tree.js
if (sourceMapOptions.sourceMapFullFilename && !sourceMapFileInline) {
var mapFilename = path.resolve(process.cwd(), sourceMapOptions.sourceMapFullFilename);
var mapDir = path.dirname(mapFilename);

if (output) {
var outputDir = path.dirname(output);
// Set sourceMapOutputFilename relative to map directory
sourceMapOptions.sourceMapOutputFilename = path.join(
path.relative(mapDir, outputDir),
path.basename(output)
);
// Set sourceMapFilename relative to output directory (for sourceMappingURL comment)
sourceMapOptions.sourceMapFilename = path.join(
path.relative(outputDir, mapDir),
path.basename(sourceMapOptions.sourceMapFullFilename)
);
} else {
// No output filename, just use basename
sourceMapOptions.sourceMapOutputFilename = path.basename(output || 'output.css');
sourceMapOptions.sourceMapFilename = path.basename(sourceMapOptions.sourceMapFullFilename);
}
} else if (!sourceMapOptions.sourceMapFullFilename && output && !sourceMapFileInline) {
// No explicit sourcemap filename, derive from output
sourceMapOptions.sourceMapOutputFilename = path.basename(output);
sourceMapOptions.sourceMapFullFilename = ''.concat(output, '.map');
} else if (!output && !sourceMapFileInline) {
console.error('the sourcemap option only has an optional filename if the css filename is given');
console.error('consider adding --source-map-map-inline which embeds the sourcemap into the css');
process.exitCode = 1;
return;
}
}

if (!input) {
Expand Down
13 changes: 9 additions & 4 deletions packages/less/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,16 @@
"scripts": {
"quicktest": "grunt quicktest",
"test": "grunt test",
"test:coverage": "c8 -r lcov -r json-summary -r text-summary -r html --include=\"lib/**/*.js\" --include=\"bin/**/*.js\" --exclude=\"dist/**\" --exclude=\"**/*.test.js\" --exclude=\"**/*.spec.js\" --exclude=\"test/**\" --exclude=\"tmp/**\" --exclude=\"**/abstract-file-manager.js\" --exclude=\"**/abstract-plugin-loader.js\" grunt shell:test && node scripts/coverage-report.js && node scripts/coverage-lines.js",
"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",
"dev": "tsc -p tsconfig.build.json -w",
"prepublishOnly": "grunt dist"
"prepublishOnly": "grunt dist",
"postinstall": "node scripts/postinstall.js"
},
"optionalDependencies": {
"errno": "^0.1.1",
Expand All @@ -66,11 +68,14 @@
"benny": "^3.6.12",
"bootstrap-less-port": "0.3.0",
"chai": "^4.2.0",
"c8": "^10.1.3",
"chalk": "^4.1.2",
"cosmiconfig": "~9.0.0",
"cross-env": "^7.0.3",
"diff": "^3.2.0",
"eslint": "^7.29.0",
"fs-extra": "^8.1.0",
"git-rev": "^0.2.1",
"glob": "~11.0.3",
"globby": "^10.0.1",
"grunt": "^1.0.4",
"grunt-cli": "^1.3.2",
Expand All @@ -80,17 +85,17 @@
"grunt-saucelabs": "^9.0.1",
"grunt-shell": "^1.3.0",
"html-template-tag": "^3.2.0",
"jest-diff": "~30.1.2",
"jit-grunt": "^0.10.0",
"less-plugin-autoprefix": "^1.5.1",
"less-plugin-clean-css": "^1.6.0",
"minimist": "^1.2.0",
"mocha": "^6.2.1",
"playwright": "1.50.1",
"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",
"playwright": "1.50.1",
"promise": "^7.1.1",
"read-glob": "^3.0.0",
"resolve": "^1.17.0",
Expand Down
Loading
Loading