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

amber-dev

Package Overview
Dependencies
Maintainers
3
Versions
39
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

amber-dev - npm Package Compare versions

Comparing version 0.6.1 to 0.7.1

lib/without-imports.js

246

lib/amberc.js

@@ -11,54 +11,6 @@ /**

/**
* Helper for concatenating Amber generated AMD modules.
* The produced output can be exported and run as an independent program.
*
* var concatenator = createConcatenator();
* concatenator.start(); // write the required AMD define header
* concatenator.add(module1);
* concatenator.addId(module1_ID);
* //...
* concatenator.finish("//some last code");
* var concatenation = concatenator.toString();
* // The variable concatenation contains the concatenated result
* // which can either be stored in a file or interpreted with eval().
*/
function createConcatenator() {
return {
elements: [],
ids: [],
add: function () {
this.elements.push.apply(this.elements, arguments);
},
addId: function () {
this.ids.push.apply(this.ids, arguments);
},
forEach: function () {
this.elements.forEach.apply(this.elements, arguments);
},
start: function () {
this.add(
'var define = (' + require('amdefine') + ')(null, function (id) { throw new Error("Dependency not found: " + id); }), requirejs = define.require;',
'define("amber/browser-compatibility", [], {});'
);
},
finish: function (realWork) {
this.add(
'define("app", ["' + this.ids.join('","') + '"], function (boot) {',
'boot.api.initialize();',
realWork,
'});',
'requirejs(["app"]);'
);
},
toString: function () {
return this.elements.join('\n');
}
};
}
var path = require('path'),
fs = require('fs'),
Promise = require('es6-promise').Promise;
Promise = require('es6-promise').Promise,
requirejs = require('requirejs');

@@ -76,7 +28,11 @@ /**

// Important: in next list, boot MUST be first
this.kernel_libraries = ['boot', 'Kernel-Objects', 'Kernel-Classes', 'Kernel-Methods',
'Kernel-Collections', 'Kernel-Infrastructure', 'Kernel-Exceptions', 'Kernel-Announcements',
'Platform-Services', 'Platform-Node'];
this.compiler_libraries = this.kernel_libraries.concat(['parser', 'Platform-ImportExport', 'Compiler-Exceptions',
'Compiler-Core', 'Compiler-AST', 'Compiler-Exceptions', 'Compiler-IR', 'Compiler-Inlining', 'Compiler-Semantic']);
this.kernel_libraries = ['amber/boot',
'amber_core/Kernel-Objects', 'amber_core/Kernel-Classes', 'amber_core/Kernel-Methods',
'amber_core/Kernel-Collections', 'amber_core/Kernel-Infrastructure',
'amber_core/Kernel-Exceptions', 'amber_core/Kernel-Announcements',
'amber_core/Platform-Services', 'amber_core/Platform-Node'];
this.compiler_libraries = this.kernel_libraries.concat(['amber/parser',
'amber_core/Platform-ImportExport', 'amber_core/Compiler-Exceptions',
'amber_core/Compiler-Core', 'amber_core/Compiler-AST', 'amber_core/Compiler-Exceptions',
'amber_core/Compiler-IR', 'amber_core/Compiler-Inlining', 'amber_core/Compiler-Semantic']);
}

@@ -90,2 +46,4 @@

return {
paths: {},
configFile: null,
load: [],

@@ -95,4 +53,2 @@ stFiles: [],

amdNamespace: 'amber_core',
libraries: [],
jsLibraryDirs: [],
compile: [],

@@ -118,7 +74,2 @@ compiled: [],

if (configuration.jsLibraryDirs != null) {
configuration.jsLibraryDirs.push(path.join(this.amber_dir, 'src'));
configuration.jsLibraryDirs.push(path.join(this.amber_dir, 'support'));
}
console.ambercLog = console.log;

@@ -133,9 +84,34 @@ if (false === configuration.verbose) {

configuration.globals = {};
configuration.kernel_libraries = this.kernel_libraries;
configuration.compiler_libraries = this.compiler_libraries;
configuration.amber_dir = this.amber_dir;
var rjsConfig;
if (configuration.configFile) {
var configSrc = fs.readFileSync(configuration.configFile, "utf8");
rjsConfig = (function () {
var require, requirejs;
requirejs = require = {
config: function (x) {
requirejs = require = x;
}
};
eval(configSrc);
return require;
})();
} else {
rjsConfig = {
paths: configuration.paths
};
}
if (!rjsConfig.paths.amber) rjsConfig.paths.amber = path.join(this.amber_dir, 'support');
if (!rjsConfig.paths.amber_core) rjsConfig.paths.amber_core = path.join(this.amber_dir, 'src');
rjsConfig.paths['text'] = require.resolve('requirejs-text').replace(/\.js$/, "");
rjsConfig.paths['amber/without-imports'] = path.join(__dirname, 'without-imports');
rjsConfig.nodeRequire = require;
rjsConfig.context = "amberc";
configuration.requirejs = requirejs.config(rjsConfig);
check_configuration(configuration)
.then(collect_st_files)
.then(resolve_kernel)
.then(create_compiler)

@@ -173,3 +149,3 @@ .then(compile)

});
};
}

@@ -180,19 +156,2 @@

* 1. current local directory
* 2. configuration.jsLibraryDirs
* 3. $AMBER/src/
* 3. $AMBER/support/
*
* @param filename name of a file without '.js' prefix
* @param configuration the main amberc configuration object
*/
function resolve_js(filename, configuration) {
var baseName = path.basename(filename, '.js');
var jsFile = baseName + '.js';
return resolve_file(jsFile, configuration.jsLibraryDirs);
};
/**
* Check if the file given as parameter exists in any of the following directories:
* 1. current local directory
* 2. $AMBER/

@@ -205,3 +164,3 @@ *

return resolve_file(filename, [configuration.amber_dir]);
};
}

@@ -235,3 +194,3 @@

});
};
}

@@ -257,36 +216,2 @@

/**
* Resolve .js files needed by kernel.
* Returns a Promise which resolves into the configuration object.
*/
function resolve_kernel(configuration) {
var kernel_files = configuration.kernel_libraries.concat(configuration.load);
return Promise.all(
kernel_files.map(function (file) {
return resolve_js(file, configuration);
})
)
.then(function (data) {
// boot.js and Kernel files need to be used first
// otherwise the global objects 'core' and 'globals' are undefined
configuration.libraries = data.concat(configuration.libraries);
return configuration;
});
}
function withImportsExcluded(data) {
var srcLines = data.split(/\r\n|\r|\n/), dstLines = [], doCopy = true;
srcLines.forEach(function (line) {
if (line.replace(/\s/g, '') === '//>>excludeStart("imports",pragmas.excludeImports);') {
doCopy = false;
} else if (line.replace(/\s/g, '') === '//>>excludeEnd("imports");') {
doCopy = true;
} else if (doCopy) {
dstLines.push(line);
}
});
return dstLines.join('\n');
}
/**
* Resolve .js files needed by compiler, read and eval() them.

@@ -299,82 +224,13 @@ * The finished Compiler gets stored in configuration.{core,globals}.

var include_files = configuration.load;
var builder;
return Promise.all(
compiler_files.map(function (file) {
return resolve_js(file, configuration);
})
)
.then(function (compilerFilesArray) {
return Promise.all(
compilerFilesArray.map(function (file) {
return new Promise(function (resolve, reject) {
console.log('Loading file: ' + file);
fs.readFile(file, function (err, data) {
if (err)
reject(err);
else
resolve(data);
});
});
})
)
})
.then(function (files) {
builder = createConcatenator();
builder.add('(function() {');
builder.start();
files.forEach(function (data) {
// data is an array where index 0 is the error code and index 1 contains the data
builder.add(data);
// matches and returns the "module_id" string in the AMD definition: define("module_id", ...)
var match = ('' + data).match(/(^|\n)define\("([^"]*)"/);
if (match) {
builder.addId(match[2]);
}
return new Promise(configuration.requirejs.bind(null, compiler_files))
.then(function (boot) {
boot.api.initialize();
configuration.core = boot.api;
configuration.globals = boot.globals;
var pluginPrefixedLibraries = include_files.map(function (each) {
return 'amber/without-imports!' + each;
});
return new Promise(configuration.requirejs.bind(null, pluginPrefixedLibraries));
})
.then(function () {
return Promise.all(
include_files.map(function (file) {
return resolve_js(file, configuration);
})
);
})
.then(function (includeFilesArray) {
return Promise.all(
includeFilesArray.map(function (file) {
return new Promise(function (resolve, reject) {
console.log('Loading library file: ' + file);
fs.readFile(file, function (err, data) {
if (err)
reject(err);
else
resolve(data);
});
});
})
)
})
.then(function (files) {
var loadIds = [];
files.forEach(function (data) {
data = data + '';
// matches and returns the "module_id" string in the AMD definition: define("module_id", ...)
var match = data.match(/^define\("([^"]*)"/);
if (match) {
loadIds.push(match[1]);
data = withImportsExcluded(data);
}
builder.add(data);
});
// store the generated smalltalk env in configuration.{core,globals}
builder.finish('configuration.core = boot.api; configuration.globals = boot.globals;');
loadIds.forEach(function (id) {
builder.add('requirejs("' + id + '");');
});
builder.add('})();');
eval(builder.toString());
console.log('Compiler loaded');

@@ -381,0 +237,0 @@

{
"name": "amber-dev",
"version": "0.6.1",
"version": "0.7.1",
"description": "Development goodies for Amber Smalltalk",

@@ -20,4 +20,6 @@ "scripts": {

"amdefine": ">=0.1.1",
"es6-promise": "^2.0.0"
"es6-promise": "^2.0.0",
"requirejs": "^2.1.19",
"requirejs-text": "^2.0.12"
}
}

@@ -17,3 +17,2 @@ module.exports = function (grunt) {

amber_dir: process.cwd(), // REQUIRED
library_dirs: ['dir1', '/usr/local/js'], // optional
verbose: true // optional

@@ -25,10 +24,9 @@ },

options: {
library_dirs: ['dir1', '/usr/local/js'], // optional
verbose: true
},
src: ['projects/HelloWorld/src/HelloWorld.st'], // REQUIRED
outputDir: 'projects/HelloWorld/src', // optional
output_dir: 'projects/HelloWorld/src', // optional
libraries: 'Web', // optional
jsGlobals: ['global1', 'global2'], // optional
amdNamespace: 'MyNamespace', // optional (default: 'amber')
amd_namespace: 'MyNamespace', // optional (default: 'amber')
},

@@ -44,7 +42,9 @@ },

amber_dir: undefined,
library_dirs: [],
configFile: null,
paths: {},
verbose: grunt.option('verbose') || false
});
this.data.verbose = options.verbose;
this.data.library_dirs = options.library_dirs;
this.data.configFile = options.configFile;
this.data.paths = options.paths;

@@ -79,5 +79,8 @@ // mark required properties

}
if (data.library_dirs != null) {
configuration.jsLibraryDirs = data.library_dirs;
if (data.configFile != null) {
configuration.configFile = data.configFile;
}
if (data.paths != null) {
configuration.paths = data.paths;
}
if (sourceFiles != null) {

@@ -84,0 +87,0 @@ configuration.stFiles = sourceFiles;

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