Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

kmc

Package Overview
Dependencies
Maintainers
2
Versions
44
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

kmc - npm Package Compare versions

Comparing version 1.0.20 to 1.0.21

test/src/package1/fix-module-name.js

8

HISTORY.md

@@ -0,1 +1,9 @@

## 2013.11.24, Version 1.0.21(Stable)
### enhancement
- combo增加输出文件的选项,方便fix module name
- combo、build方法支持使用对象形式传参
- fixModuleName默认为true
## 2013.11.22, Version 1.0.20(Stable)

@@ -2,0 +10,0 @@

24

index.js

@@ -60,2 +60,10 @@ /**

combo = [];
// for object arguments.
if(_.isPlainObject(inputFilePath) && inputFilePath.src){
outputFilePath = inputFilePath.dest;
outputCharset = inputFilePath.outputCharset;
depFile = inputFilePath.depPath;
traverse = inputFilePath.traverse;
}
if(_.isString(inputFilePath)){

@@ -129,16 +137,24 @@ var target = path.resolve(inputFilePath);

},
combo: function(inputFile, depFileName, depFileCharset, fixModuleName, returnDependencies){
combo: function(inputFile, depFileName, depFileCharset, fixModuleName, returnDependencies, outputDir){
var self = this,
content,
config;
if(_.isObject(inputFile)){
depFileName = inputFile.depPath;
depFileCharset = inputFile.depCharset;
fixModuleName = inputFile.fixModuleName;
returnDependencies = inputFile.showFullResult;
outputDir = inputFile.dest;
inputFile = inputFile.src;
}
self._config = parseConfig.check(self._config, inputFile);
config = _.cloneDeep(self._config);
fixModuleName = fixModuleName === true;
fixModuleName = fixModuleName !== false;
var c = new Compiler(config);
var result = c.analyze(inputFile);
content = c.combo(fixModuleName);
content = c.combo(fixModuleName, outputDir);
if(content && depFileName){
utils.writeFileSync(depFileName, content, depFileCharset);
}
return returnDependencies === true ? { files: [result], success: true, modules: c.modules } : content;
return returnDependencies === true ? { files: [result], success: true, modules: c.modules, content: content } : content;
},

@@ -145,0 +161,0 @@ clean: function(){

@@ -400,5 +400,11 @@ /**

};
Compiler.prototype.combo = function(fixModuleName){
var self = this,
content = [];
Compiler.prototype.combo = function(fixModuleName, outputDir){
var self = this;
var content = [];
if(outputDir){
outputDir = path.resolve(outputDir);
if(!fs.existsSync(path.resolve(outputDir))){
utils.mkdirsSync(outputDir);
}
}
if(_.isObject(self.modules)){

@@ -416,3 +422,12 @@ _.forEach(self.modules, function(mod, modName){

var buffer = iconv.encode(modContent, mod.charset);
fs.writeFileSync(mod.path, buffer);
var outputPath = mod.path;
if(outputDir){
var relativePath = mod.name;
if(mod.pkg && mod.pkg.ignorePackageNameInUri){
relativePath = mod.name.replace(mod.pkg.name + '/', '');
}
outputPath = path.resolve(outputDir, relativePath + '.' + mod.type);
utils.mkdirsSync(path.dirname(outputPath));
}
fs.writeFileSync(outputPath, buffer);
}

@@ -419,0 +434,0 @@ });

2

package.json
{
"name":"kmc",
"version":"1.0.20",
"version":"1.0.21",
"description":"KISSY Module Compiler",

@@ -5,0 +5,0 @@ "author":"daxingplay <daxingplay@gmail.com>",

@@ -36,3 +36,3 @@ # ModuleCompiler

git clone git://github.com/daxingplay/ModuleCompiler.git
git clone git://github.com/daxingplay/kmc.git

@@ -96,25 +96,77 @@ **注意**: 新版本的KISSY Module Compiler的npm包已经更名为kmc,如果使用老版本(此版已经不再维护),请`npm install module-compiler`

* 打包一个文件/目录
* @param inputPath {String} 源文件/目录的绝对路径.
* @param outputPath {String} 打包出来的文件/目录的路径.
* @param src {String} 源文件/目录的绝对路径.
* @param dest {String} 打包出来的文件/目录的路径.
* @param outputCharset {String} 输出编码,这里的设置会覆盖config.charset中的设置,默认UTF-8
* @return {Object} 打包出来的文件信息
*/
kmc.build('xxx.js', 'xxx.combine.js', 'gbk');
kmc.build({
src: 'xxx.js',
dest: 'xxx.combine.js',
outputCharset: 'gbk'
});
```
更详细的文档,请参见[wiki](https://github.com/daxingplay/ModuleCompiler/wiki)。
更详细的文档,请参见[wiki](https://github.com/daxingplay/kmc/wiki)。
### API汇总
* kmc.config(cfg):配置包,返回当前所有配置信息。如果不带参数,直接返回当前所有配置信息。
* kmc.analyze(inputPath):只分析该文件依赖,不打包。
* kmc.build(inputPath, outputPath, outputCharset, depFilePath, traverse):打包函数,具体见wiki
* kmc.combo(inputPath, depFilePath, depFileCharset, fixModuleName): 不打包,只生成KISSY 1.3的自动combo依赖文件,fixModuleName默认为false
* kmc.clean(): 可以清空config中的设置。因为ModuleCompiler是单例运行,所以如果出现一些特别情况,可以在config前执行clean方法清空之前的配置。
#### 配置
配置包,返回当前所有配置信息。如果不带参数,直接返回当前所有配置信息。
```js
kmc.config(cfg);
```
#### 分析依赖
只分析该文件依赖,不打包。
```js
kmc.analyze(src);
```
#### 打包
打包函数,具体见wiki
```js
kmc.build({
src: '\xxx\xxx\src\a.js', // 需要打包的文件
dest: '\xxx\xxx\build\a.js', // 打包后文件输出的路径
outputCharset: 'gbk', // 所有的输出文件编码,包括依赖文件
depPath: '\xxx\xxx\dep.js' // 依赖文件的路径
});
```
#### 生成依赖
不打包,只生成KISSY 1.3的自动combo依赖文件
```js
kmc.combo({
src: '', // 需要打包or生成依赖关系的文件
dest: '', // 模块最后输出的路径(fixModuleName === true的时候必须配置这个选项,否则源文件的内容会被修改)
depPath: '', // 依赖文件的输出路径
depCharset: '', // 依赖文件的编码
fixModuleName: '', // 是否给文件添加模块名,默认为true
showFullResult: '' // 函数的return结果会以对象的形式输出丰富的信息
});
```
#### 清空配置
可以清空config中的设置。因为ModuleCompiler是单例运行,所以如果出现一些特别情况,可以在config前执行clean方法清空之前的配置。
```js
kmc.clean();
```
## CHANGELOG
[版本更新记录](https://github.com/daxingplay/ModuleCompiler/blob/master/HISTORY.md)
[版本更新记录](https://github.com/daxingplay/kmc/blob/master/HISTORY.md)
## License
遵守 "MIT":https://github.com/daxingplay/ModuleCompiler/blob/master/LICENSE.md 协议
遵守 "MIT":https://github.com/daxingplay/kmc/blob/master/LICENSE.md 协议

@@ -931,82 +931,155 @@ /**

});
//describe('When build a directory and have ignore config', function(){
// var result;
//
// var inputDir = path.resolve(srcPath, 'package1/'),
// outputDir = path.resolve(distPath, 'package1-dir/');
//
// before(function(){
// ModuleCompiler.config({
// packages: [{
// name: 'package1',
// path: srcPath,
// charset: 'gbk'
// }],
// silent: true,
// ignoreFiles: '.js',
// charset: 'gbk'
// });
// result = ModuleCompiler.build(inputDir, outputDir);
// });
//
// after(function(){
// ModuleCompiler.clean();
// });
//
// it('should have no files', function(){
// result.files.length.should.equal(0);
// });
//});
//describe('When build using module name', function(){
// var result;
//
// var outputFile = path.resolve(distPath, 'package1/one-package-simple.js');
//
// before(function(){
// ModuleCompiler.config({
// packages: [{
// name: 'package1',
// path: srcPath,
// charset: 'gbk'
// }],
// silent: true,
// charset: 'gbk'
// });
// result = ModuleCompiler.build('package1/one-package-simple.js', outputFile);
// });
//
// after(function(){
// ModuleCompiler.clean();
// });
//
// it('should have file generated.', function(){
// var exists = false;
// if(fs.existsSync(outputFile)){
// exists = true;
// }
// exists.should.equal(true);
// });
//
// it('should build succesfull without any errors.', function(){
// result.should.have.property('success', true);
// });
//
// it('should contain a file list.', function(){
// result.should.have.property('files').with.lengthOf('1');
// });
//
// it('should have proper main module.', function(){
// var file = result.files[0];
// file.name.should.equal('package1/one-package-simple');
// file.should.have.property('submods').with.lengthOf('2');
// });
//
// it('should have some modules in combo file', function(){
// var submods = result.files[0].submods;
// submods[0].name.should.equal('package1/mods/mod1');
// submods[0].status.should.equal('ok');
// submods[1].name.should.equal('package1/mods/mod2');
// submods[1].status.should.equal('ok');
// });
//});
describe('When fix module name', function(){
var result;
var inputFile = path.resolve(srcPath, 'package1/fix-module-name.js'),
depFile = path.resolve(distPath, 'package1/fix-module-name-dep.js'),
outputDir = path.resolve(distPath, './fix-module-name');
before(function(){
ModuleCompiler.config({
packages: [{
name: 'package1',
path: srcPath,
charset: 'gbk'
}],
silent: true
});
result = ModuleCompiler.combo(inputFile, depFile, '', true, true, outputDir);
});
after(function(){
ModuleCompiler.clean();
});
it('should have dep file', function(){
fs.existsSync(depFile).should.equal(true);
});
it('should have new module files', function(){
fs.existsSync(path.resolve(outputDir, './package1/fix-module-name.js')).should.equal(true);
fs.existsSync(path.resolve(outputDir, './package1/mods/mod2.js')).should.equal(true);
});
it('should have added module names to files', function(){
/package1\/fix\-module\-name/.test(fs.readFileSync(path.resolve(outputDir, './package1/fix-module-name.js'))).should.equal(true);
/package1\/mods\/mod2/.test(fs.readFileSync(path.resolve(outputDir, './package1/mods/mod2.js'))).should.equal(true);
});
});
describe('When fix module name which package name is ignored', function(){
var result;
var inputFile = path.resolve(srcPath, 'package1/fix-module-name2.js'),
depFile = path.resolve(distPath, 'package1/fix-module-name2-dep.js'),
outputDir = path.resolve(distPath, './fix-module-name2');
before(function(){
ModuleCompiler.config({
packages: [{
name: 'pkg1',
path: path.resolve(srcPath, './package1'),
ignorePackageNameInUri: true
}],
silent: true
});
result = ModuleCompiler.combo(inputFile, depFile, '', true, true, outputDir);
});
after(function(){
ModuleCompiler.clean();
});
it('should have dep file', function(){
fs.existsSync(depFile).should.equal(true);
});
it('should have new module files', function(){
fs.existsSync(path.resolve(outputDir, './fix-module-name2.js')).should.equal(true);
fs.existsSync(path.resolve(outputDir, './mods/mod2.js')).should.equal(true);
});
it('should have proper module names', function(){
result.modules.should.have.property('pkg1/fix-module-name2');
});
it('should have added module names to files', function(){
/pkg1\/fix\-module\-name2/.test(fs.readFileSync(path.resolve(outputDir, './fix-module-name2.js'))).should.equal(true);
/pkg1\/mods\/mod2/.test(fs.readFileSync(path.resolve(outputDir, './mods/mod2.js'))).should.equal(true);
});
});
describe('When pass an object as arguments for build', function(){
var result;
var inputFile = path.resolve(srcPath, 'package1/one-package-simple.js'),
outputFile = path.resolve(distPath, 'package1/one-package-simple.js'),
depPath = path.resolve(distPath, 'dep/package1/one-package-simple.js');
before(function(){
ModuleCompiler.config({
packages: [{
name: 'package1',
path: srcPath,
charset: 'gbk'
}],
silent: true,
charset: 'gbk'
});
result = ModuleCompiler.build({
src: inputFile,
dest: outputFile,
depPath: depPath,
outputCharset: 'utf8'
});
});
after(function(){
ModuleCompiler.clean();
});
it('should have proper file generated', function(){
fs.existsSync(outputFile).should.equal(true);
fs.existsSync(depPath).should.equal(true);
});
});
describe('When pass an object as arguments for combo', function(){
var result;
var inputFile = path.resolve(srcPath, 'package1/fix-module-name.js'),
depFile = path.resolve(distPath, 'package1/fix-module-name-dep.js'),
outputDir = path.resolve(distPath, './fix-module-name3');
before(function(){
ModuleCompiler.config({
packages: [{
name: 'package1',
path: srcPath,
charset: 'gbk'
}],
silent: true,
charset: 'gbk'
});
result = ModuleCompiler.combo({
src: inputFile,
dest: outputDir,
depPath: depFile,
depCharset: 'utf8',
fixModuleName: true,
showFullResult: true
});
});
after(function(){
ModuleCompiler.clean();
});
it('should have proper file generated', function(){
fs.existsSync(depFile).should.equal(true);
fs.existsSync(path.resolve(outputDir, './package1/fix-module-name.js')).should.equal(true);
fs.existsSync(path.resolve(outputDir, './package1/mods/mod2.js')).should.equal(true);
});
});
/**
* mod2
* mod2, gbk encoded.
* @author: daxingplay<daxingplay@gmail.com>

@@ -4,0 +4,0 @@ * @date: 12-9-26

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc