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

调整解析

master 1.0.0
yutent 2023-06-20 11:24:02 +08:00
parent 6e3b874108
commit 92340a43ee
11 changed files with 13 additions and 58 deletions

View File

@ -6,7 +6,7 @@ Es.buildSync({
outdir: 'dist', outdir: 'dist',
platform: 'node', platform: 'node',
format: 'esm', format: 'esm',
// minify: true, minify: true,
bundle: true, bundle: true,
target: 'node12' target: 'node12'
}) })

View File

@ -1,6 +1,6 @@
{ {
"name": "@bytedo/less", "name": "@bytedo/less",
"version": "0.0.1", "version": "1.0.0",
"type": "module", "type": "module",
"description": "less精简版", "description": "less精简版",
"homepage": "http://lesscss.org", "homepage": "http://lesscss.org",

View File

@ -10,12 +10,10 @@ import PluginLoader from './plugin-loader'
import fs from 'fs' import fs from 'fs'
import options from '../less/default-options' import options from '../less/default-options'
// allow people to create less with their own environment
less.createFromEnvironment = createFromEnvironment
less.PluginLoader = PluginLoader less.PluginLoader = PluginLoader
less.fs = fs // less.fs = fs
less.FileManager = FileManager // less.FileManager = FileManager
less.UrlFileManager = UrlFileManager // less.UrlFileManager = UrlFileManager
// Set up options // Set up options
less.options = options less.options = options

View File

@ -7,7 +7,6 @@ const isUrlRe = /^(?:https?:)?\/\//i
import url from 'url' import url from 'url'
let request let request
import AbstractFileManager from '../less/environment/abstract-file-manager.js' import AbstractFileManager from '../less/environment/abstract-file-manager.js'
import logger from '../less/logger'
const UrlFileManager = function () {} const UrlFileManager = function () {}
UrlFileManager.prototype = Object.assign(new AbstractFileManager(), { UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
@ -53,7 +52,7 @@ UrlFileManager.prototype = Object.assign(new AbstractFileManager(), {
} }
body = body.toString('utf8') body = body.toString('utf8')
if (!body) { if (!body) {
logger.warn( console.warn(
`Warning: Empty body (HTTP ${resp.statusCode}) returned by "${urlStr}"` `Warning: Empty body (HTTP ${resp.statusCode}) returned by "${urlStr}"`
) )
} }

View File

@ -3,8 +3,6 @@
* environment, file managers, and plugin manager * environment, file managers, and plugin manager
*/ */
import logger from '../logger'
class Environment { class Environment {
constructor(externalEnvironment, fileManagers) { constructor(externalEnvironment, fileManagers) {
this.fileManagers = fileManagers || [] this.fileManagers = fileManagers || []
@ -32,12 +30,12 @@ class Environment {
getFileManager(filename, currentDirectory, options, environment, isSync) { getFileManager(filename, currentDirectory, options, environment, isSync) {
if (!filename) { if (!filename) {
logger.warn( console.warn(
'getFileManager called with no filename.. Please report this issue. continuing.' 'getFileManager called with no filename.. Please report this issue. continuing.'
) )
} }
if (currentDirectory === undefined) { if (currentDirectory === undefined) {
logger.warn( console.warn(
'getFileManager called with null directory.. Please report this issue. continuing.' 'getFileManager called with null directory.. Please report this issue. continuing.'
) )
} }

View File

@ -1,7 +1,6 @@
import Quoted from '../tree/quoted' import Quoted from '../tree/quoted'
import URL from '../tree/url' import URL from '../tree/url'
import * as utils from '../utils' import * as utils from '../utils'
import logger from '../logger'
export default environment => { export default environment => {
const fallback = (functionThis, node) => const fallback = (functionThis, node) =>
@ -71,7 +70,7 @@ export default environment => {
environment environment
) )
if (!fileSync.contents) { if (!fileSync.contents) {
logger.warn( console.warn(
`Skipped data-uri embedding of ${filePath} because file not found` `Skipped data-uri embedding of ${filePath} because file not found`
) )
return fallback(this, filePathNode || mimetypeNode) return fallback(this, filePathNode || mimetypeNode)

View File

@ -2,7 +2,6 @@ import contexts from './contexts'
import Parser from './parser/parser' import Parser from './parser/parser'
import LessError from './less-error' import LessError from './less-error'
import * as utils from './utils' import * as utils from './utils'
import logger from './logger'
export default function (environment) { export default function (environment) {
// FileInfo = { // FileInfo = {
@ -49,7 +48,7 @@ export default function (environment) {
const importedEqualsRoot = fullPath === importManager.rootFilename const importedEqualsRoot = fullPath === importManager.rootFilename
if (importOptions.optional && e) { if (importOptions.optional && e) {
callback(null, { rules: [] }, false, null) callback(null, { rules: [] }, false, null)
logger.info( console.info(
`The file ${fullPath} was skipped because it was not found and the import was marked optional.` `The file ${fullPath} was skipped because it was not found and the import was marked optional.`
) )
} else { } else {

View File

@ -11,7 +11,6 @@ import LessError from './less-error'
import transformTree from './transform-tree' import transformTree from './transform-tree'
import * as utils from './utils' import * as utils from './utils'
import PluginManager from './plugin-manager' import PluginManager from './plugin-manager'
import logger from './logger'
import SourceMapOutput from './source-map-output' import SourceMapOutput from './source-map-output'
import SourceMapBuilder from './source-map-builder' import SourceMapBuilder from './source-map-builder'
import ParseTree from './parse-tree' import ParseTree from './parse-tree'
@ -54,8 +53,7 @@ export default function (environment, fileManagers) {
LessError, LessError,
transformTree, transformTree,
utils, utils,
PluginManager, PluginManager
logger
} }
// Create a public API // Create a public API

View File

@ -1,34 +0,0 @@
export default {
error: function (msg) {
this._fireEvent('error', msg)
},
warn: function (msg) {
this._fireEvent('warn', msg)
},
info: function (msg) {
this._fireEvent('info', msg)
},
debug: function (msg) {
this._fireEvent('debug', msg)
},
addListener: function (listener) {
this._listeners.push(listener)
},
removeListener: function (listener) {
for (let i = 0; i < this._listeners.length; i++) {
if (this._listeners[i] === listener) {
this._listeners.splice(i, 1)
return
}
}
},
_fireEvent: function (type, msg) {
for (let i = 0; i < this._listeners.length; i++) {
const logFunction = this._listeners[i][type]
if (logFunction) {
logFunction(msg)
}
}
},
_listeners: []
}

View File

@ -1,6 +1,5 @@
import LessError from './less-error' import LessError from './less-error'
import transformTree from './transform-tree' import transformTree from './transform-tree'
import logger from './logger'
export default function (SourceMapBuilder) { export default function (SourceMapBuilder) {
class ParseTree { class ParseTree {
@ -22,7 +21,7 @@ export default function (SourceMapBuilder) {
try { try {
const compress = Boolean(options.compress) const compress = Boolean(options.compress)
if (compress) { if (compress) {
logger.warn( console.warn(
'The compress option has been deprecated. ' + 'The compress option has been deprecated. ' +
'We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.' 'We recommend you use a dedicated css minifier, for instance see less-plugin-clean-css.'
) )

View File

@ -4,7 +4,6 @@
*/ */
import tree from '../tree' import tree from '../tree'
import Visitor from './visitor' import Visitor from './visitor'
import logger from '../logger'
import * as utils from '../utils' import * as utils from '../utils'
/* jshint loopfunc:true */ /* jshint loopfunc:true */
@ -144,7 +143,7 @@ class ProcessExtendsVisitor {
if (!indices[`${extend.index} ${selector}`]) { if (!indices[`${extend.index} ${selector}`]) {
indices[`${extend.index} ${selector}`] = true indices[`${extend.index} ${selector}`] = true
logger.warn(`extend '${selector}' has no matches`) console.warn(`extend '${selector}' has no matches`)
} }
}) })
} }