I have the following rule but it isn't working because the select is evaluating target platform instead of host platform or execution platform.
Does anyone know how to make it work?
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
build_script_env = select({
"#bazel_tools//src/conditions:linux_aarch64": {
"PROTOC": "$(execpath #com_google_protobuf_protoc_linux_aarch64//:protoc)",
"RUSTFMT": "$(execpath #rust_linux_aarch64//:rustfmt_bin)",
},
"#bazel_tools//src/conditions:linux_x86_64": {
"PROTOC": "$(execpath #com_google_protobuf_protoc_linux_x86_64//:protoc)",
"RUSTFMT": "$(execpath #rust_linux_x86_64//:rustfmt_bin)",
},
"#bazel_tools//src/conditions:darwin_arm64": {
"PROTOC": "$(execpath #com_google_protobuf_protoc_macos_aarch64//:protoc)",
"RUSTFMT": "$(execpath #rust_darwin_aarch64//:rustfmt_bin)",
},
"#bazel_tools//src/conditions:darwin_x86_64": {
"PROTOC": "$(execpath #com_google_protobuf_protoc_macos_x86_64//:protoc)",
"RUSTFMT": "$(execpath #rust_darwin_x86_64//:rustfmt_bin)",
},
}),
crate_features = [
"transport",
],
data = [
"//api/protos:protos",
"#com_google_protobuf//:protoc",
"#com_google_protobuf//:well_known_protos",
] + select({
"#bazel_tools//src/conditions:linux_aarch64": [
"#rust_linux_aarch64//:rustfmt_bin",
"#com_google_protobuf_protoc_linux_aarch64//:protoc",
],
"#bazel_tools//src/conditions:linux_x86_64": [
"#rust_linux_x86_64//:rustfmt_bin",
"#com_google_protobuf_protoc_linux_x86_64//:protoc",
],
"#bazel_tools//src/conditions:darwin_arm64": [
"#rust_darwin_aarch64//:rustfmt_bin",
"#com_google_protobuf_protoc_macos_aarch64//:protoc",
],
"#bazel_tools//src/conditions:darwin_x86_64": [
"#rust_darwin_x86_64//:rustfmt_bin",
"#com_google_protobuf_protoc_macos_x86_64//:protoc",
],
}),
deps = [
"#raze__tonic_build__0_6_2//:tonic_build",
],
)
I know there is an exex_compatible_with option for each rule but this doesn't help. I would have to create one rule per execution platform but then select again each rule given the platform.
In the end, I solve it with:
cargo_build_script(
name = "build_script",
srcs = ["build.rs"],
build_script_env = {
"PROTOC": "$(execpath #com_google_protobuf//:protoc)",
"RUSTFMT": "$(rootpath #rules_rust//rust/toolchain:current_rustfmt_files)",
},
crate_features = [
"transport",
],
data = [
"//api/protos",
"#com_google_protobuf//:well_known_protos",
"#rules_rust//rust/toolchain:current_rustfmt_files",
],
tools = [
"#com_google_protobuf//:protoc",
],
deps = all_crate_deps(
normal = True,
normal_dev = True,
),
)
Execution platform is handle inside the rule.
Related
My google foo is failing my here folks. The issue is clearly the underscores in the MAX_UID which is easy enough to fix manually but not when I'm running the deployment.
Any ideas about what loader I need and where to configure this? It seems to be #babel/preset-env but I'm struggling to get this configured as a laoder
ERROR in ./node_modules/bootstrap/js/src/util/index.js 8:17
Module parse failed: Identifier directly after number (8:17)
File was processed with these loaders:
* ./node_modules/babel-loader/lib/index.js
You may need an additional loader to handle the result of these loaders.
| */
|
> const MAX_UID = 1_000_000;
| const MILLISECONDS_MULTIPLIER = 1000;
| const TRANSITION_END = 'transitionend';
# ./node_modules/bootstrap/js/src/alert.js 8:0-50 78:0-18
# ./app/javascript/js/bootstrap_js_files.js
# ./app/javascript/packs/application.js
# multi ./app/javascript/packs/application.js ./app/javascript/packs/application.scss
babel.config.js
module.exports = function (api) {
var validEnv = ['development', 'test', 'production', 'staging']
var currentEnv = api.env()
var isDevelopmentEnv = api.env('development')
var isProductionEnv = api.env('production')
var isTestEnv = api.env('test')
if (!validEnv.includes(currentEnv)) {
throw new Error(
'Please specify a valid `NODE_ENV` or ' +
'`BABEL_ENV` environment variables. Valid values are "development", ' +
'"test", and "production". Instead, received: ' +
JSON.stringify(currentEnv) +
'.'
)
}
return {
presets: [
isTestEnv && [
'#babel/preset-env',
{
targets: {
node: 'current'
}
}
],
(isProductionEnv || isDevelopmentEnv) && [
'#babel/preset-env',
{
forceAllTransforms: true,
useBuiltIns: 'entry',
corejs: 3,
modules: false,
exclude: ['transform-typeof-symbol']
}
]
].filter(Boolean),
plugins: [
'babel-plugin-macros',
'#babel/plugin-syntax-dynamic-import',
isTestEnv && 'babel-plugin-dynamic-import-node',
'#babel/plugin-transform-destructuring',
[
'#babel/plugin-proposal-class-properties',
{
loose: true
}
],
[
'#babel/plugin-proposal-object-rest-spread',
{
useBuiltIns: true
}
],
[
'#babel/plugin-proposal-private-methods',
{
loose: true
}
],
[
'#babel/plugin-proposal-private-property-in-object',
{
loose: true
}
],
[
'#babel/plugin-transform-runtime',
{
helpers: false
}
],
[
'#babel/plugin-transform-regenerator',
{
async: false
}
]
].filter(Boolean)
}
}
I migrated angular4 application to Angular7 and resolved the dev and prod builds but AOT build is not transpiling the application code(app.module). The main and polyfill bundle size is only 1 kb each. looking at the output console it seems it is not compiling any module.
webpack.config.js
:
/**
* #author: #AngularClass
*/
const webpack = require('webpack');
const helpers = require('./helpers');
const ngw = require('#ngtools/webpack');
const AssetsPlugin = require('assets-webpack-plugin');
const NormalModuleReplacementPlugin = require('webpack/lib/NormalModuleReplacementPlugin');
const ContextReplacementPlugin = require('webpack/lib/ContextReplacementPlugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CheckerPlugin = require('awesome-typescript-loader').CheckerPlugin;
const HtmlElementsPlugin = require('./html-elements-plugin');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const LoaderOptionsPlugin = require('webpack/lib/LoaderOptionsPlugin');
const ScriptExtHtmlWebpackPlugin = require('script-ext-html-webpack-plugin');
const HMR = helpers.hasProcessFlag('hot');
const AOT = Boolean(process.env.BUILD_AOT) || helpers.hasNpmFlag('aot');
let METADATA = {
isDevServer: helpers.isWebpackDevServer(),
HMR
};
const sassConfig = require('./scss-config.common');
console.info(`[BUILD STARTED WITH ${AOT ? 'AOT' : 'WITHOUT AOT'}]`);
module.exports = function (options) {
const isProd = options.env === 'production';
const envString = isProd ? 'prod' : 'dev';
METADATA = Object.assign({}, METADATA, require(`./environment/meta-${envString}`));
return {
target: "web",
entry: {
'polyfills': './src/polyfills.browser.ts',
'main': AOT ? './src/main.browser.aot.ts' :
'./src/main.browser.ts'
},
resolve: {
alias: {
'tslib$': 'tslib/tslib.es6.js',
},
extensions: ['.ts', '.js', '.json'],
modules: [helpers.root('src'), helpers.root('node_modules')],
},
module: {
rules: [
{
test: /(?:\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
loader: '#ngtools/webpack'
},
{
test: /\.css$/,
use: [
`to-string-loader${isProd? '' : '?sourceMap'}`,
`css-loader?${JSON.stringify({ sourceMap: !isProd, importLoaders: 1 })}`,
'postcss-loader',
],
exclude: [helpers.root('src', 'styles')]
},
{
test: /\.scss$/,
use: [
`to-string-loader${isProd? '' : '?sourceMap'}`,
`css-loader?${JSON.stringify({ sourceMap: !isProd, importLoaders: 2 })}`,
'postcss-loader',
{
loader: 'sass-loader',
options: {
includePaths: sassConfig.includePaths,
sourceMap: !isProd
}
}
],
exclude: [helpers.root('src', 'styles')]
},
{
test: /\.html$/,
// use: { loader: 'html-loader' },
use: 'raw-loader',
exclude: [helpers.root('src/index.html')]
},
{
test: /\.(jpg|png|gif)$/,
use: 'file-loader'
},
{
test: /\.(eot|woff2?|svg|ttf)([\?]?.*)$/,
use: 'file-loader'
}
],
},
plugins: [
new webpack.ProvidePlugin({
'__assign': ['tslib', '__assign'],
'__extends': ['tslib', '__extends'],
}),
new AssetsPlugin({
path: helpers.root('dist'),
filename: 'webpack-assets.json',
prettyPrint: true
}),
new CheckerPlugin(),
new ContextReplacementPlugin( /(.+)?angular(\\|\/)core(.+)?/, helpers.root('./src'), {} ),
new CopyWebpackPlugin([
{ from: 'src/assets', to: 'assets' },
{ from: 'src/meta'}
],
isProd ? { ignore: [ 'mock-data/**/*' ] } : undefined
),
new HtmlWebpackPlugin({
minify: isProd ? {
removeComments: true,
collapseWhitespace: true,
collapseBooleanAttributes: true,
decodeEntities: true,
processConditionalComments: true,
} : false,
template: 'src/index.html',
title: METADATA.title,
metadata: METADATA,
chunksSortMode: "manual",
chunks: ['polyfills', 'vendor', 'main'],
inject: false
}),
new ScriptExtHtmlWebpackPlugin({
defaultAttribute: 'defer'
}),
new HtmlElementsPlugin({
headTags: require('./head-config.common')(envString)
}),
new LoaderOptionsPlugin({}),
new NormalModuleReplacementPlugin(
/facade(\\|\/)async/,
helpers.root('node_modules/#angular/core/src/facade/async.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)collection/,
helpers.root('node_modules/#angular/core/src/facade/collection.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)errors/,
helpers.root('node_modules/#angular/core/src/facade/errors.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)lang/,
helpers.root('node_modules/#angular/core/src/facade/lang.js')
),
new NormalModuleReplacementPlugin(
/facade(\\|\/)math/,
helpers.root('node_modules/#angular/core/src/facade/math.js')
),
new ngw.AngularCompilerPlugin({
tsConfigPath: helpers.root('tsconfig.webpack.json'),
entryModule: helpers.root('src', 'app/app.module#AppModule'),
sourceMap: true,
skipCodeGeneration: true
})
],
node: {
global: true,
crypto: 'empty',
process: true,
module: false,
clearImmediate: false,
setImmediate: false,
fs: 'empty'
},
optimization: {
splitChunks: {
cacheGroups: {
polyfills: {
name: 'polyfills',
chunks: (chunk) => {
return chunk.name === 'polyfills';
}
},
vendor: {
test: /[\\/]node_modules[\\/]/,
name: 'vendor',
chunks: (chunk) => {
return chunk.name === 'main';
}
}
}
}
}
};
}
tsconfig.webpack.json:
{
"compilerOptions": {
"target": "es5",
"module": "es2015",
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"noEmit": true,
"noEmitHelpers": true,
"importHelpers": true,
"paths": { "tslib": ["./node_modules/tslib/tslib.d.ts"] },
"baseUrl": "./",
"strictNullChecks": false,
"lib": [
"es2015",
"dom"
],
"typeRoots": [
"node_modules/#types"
],
"types": [
"hammerjs",
"node"
]
},
"exclude": [
"node_modules",
"dist",
"src/**/*.spec.ts",
"src/**/*.e2e.ts"
],
"awesomeTypescriptLoaderOptions": {
"forkChecker": true,
"useWebpackText": true
},
"angularCompilerOptions": {
"skipMetadataEmit": true,
"skipTemplateCodegen" : false
},
"compileOnSave": false,
"buildOnSave": false,
"atom": {
"rewriteTsconfig": false
}
}
Angular- V7
Webpack - 4
Node - 8.11.1
Finally, I managed to resolve this and the root cause was a silly one.
As my project is a legacy one so there are many unnecessary configurations and one such was "noEmit: true" in 'compilerOptions' in 'tsconfig.webpack.json' file.
After removing this property the artifacts are generating properly.
I have successfully used "spreadsheets#get" request of Google Sheets API for a specified range, and done some calculation on each of the items in the array, storing them to a new array.
Now I need to update another range in the Google Sheet with the array items I have calculated.
I have successfully fetched data from a single cell, done calculations on that value, and written the new data to another cell. But when I am working on a range of cells, I get the error
"Requested writing within range [BILLING!D2:D], but tried writing to column [E]"
where [BILLING! D2:D] is the range I wanted to update.
Here's some of my code
Reading Data
const sheets = google.sheets({version: 'v4', auth});
let ranges = ['BILLING!A2:A']
sheets.spreadsheets.values.get({
spreadsheetId: '1F1ed24fgZIQChueq1AGrKIYRXKrX-vK3RAIYKd5lVrE',
range: ranges,
}, (err, res) => {
let sma_array = [];
async(res.data.values, (value, callback) => {
let id = value[0];
let url = 'https://www.quandl.com/api/v3/datasets/BSE/BOM' + id + '?limit=57&api_key=' + MY_API_KEY;
reqs.requestFun(url, id).then((result, err) => {
sma_array.push(result)
console.log(id,result)
setTimeout(function () { callback(); }, 500);
})
}, function (err) {
writing(sma_array)
});
})
Input array from A2:A:-
[ [ '532424' ],
[ '500003' ],
[ '524634' ],
[ '531978' ],
[ '500493' ],
[ '532321' ],
[ '530307' ],
[ '532622' ],
[ '500300' ],
[ '530001' ],
[ '532457' ],
[ '524494' ],
[ '524731' ],
[ '500233' ],
[ '532714' ],
[ '524500' ],
[ '539229' ],
[ '524084' ],
[ '538019' ],
[ '533179' ],
[ '523539' ],
[ '532805' ],
[ '500367' ],
[ '531431' ],
[ '503811' ],
[ '532343' ],
[ '504212' ],
[ '507880' ],
[ '532953' ],
[ '540743' ] ]
Writing Data
let writing = function (sma_array) {
console.log(sma_array)
let values = [
sma_array
]
const resource = {
values: values
}
let ranges = ['BILLING!D2:D']
sheets.spreadsheets.values.update({
spreadsheetId: '1F1ed24fgZIQChueq1AGrKIYRXKrX-vK3RAIYKd5lVrE',
range: ranges,
valueInputOption: 'RAW',
resource: resource,
}, (err, result) => {
if (err) {
// Handle error
console.log(err);
} else {
console.log('%d cells updated.', result.updatedCells);
}
});
}
The array that needs to get an update to D2:D : -
[ [ 702.8052631578946,
198.67719298245612,
105.9236842105263,
1137.5780701754388,
496.70263157894743,
329.87456140350884,
78.04912280701757,
115.24473684210525,
784.7464912280702,
490.9464912280701,
56.51228070175439,
841.3201754385965,
498.77192982456154,
554.2035087719298,
268.8666666666667,
199.00438596491227,
37.27543859649123,
2592.591228070176,
27.73684210526315,
626.8912280701755,
205.12368421052628,
85.49035087719298,
40.75175438596491,
391.38947368421043,
369.10789473684207,
488.36315789473656,
227.23596491228068,
458.780701754386,
206.2780701754385,
208.4875856548958 ] ]
Error
errors:
[ { message:
'Requested writing within range [BILLING!D2:D3], but tried writing to column [E]',
domain: 'global',
reason: 'badRequest' } ] }
The Problem solved by changing majorDimension of output to column or by changing output array as like major dimension=ROW.
Before my array was like array = [1,2,3,4] and now changed to array = [[1],[2],[3],[3]].
For output, if the spreadsheet data is: A1=1,B1=2,A2=3,B2=4, then requesting range=A1:B2,majorDimension=ROWS will return [[1,2],[3,4]], whereas requesting range=A1:B2,majorDimension=COLUMNS will return [[1,3],[2,4]].
For input, with range=A1:B2,majorDimension=ROWS then [[1,2],[3,4]] will set A1=1,B1=2,A2=3,B2=4. With range=A1:B2,majorDimension=COLUMNS then [[1,2],[3,4]] will set A1=1,B1=3,A2=2,B2=4.
I'm developing an Apigility driven application based on the Zend Framework 2.
I want my application to provide nested responses for both -- single items and lists:
/projects/1
{
"id": "1",
"title": "...",
...
"_embedded": {
"images": [
{
"id": "1",
"project_id": "1",
"title": "...",
...
},
{
"id": "2",
"project_id": "1",
"title": "...",
...
}
]
},
...
}
/projects
{
...
"_embedded": {
"projects": [
{
"id": "1",
"title": "...",
...
"_embedded": {
"images": [
{
"id": "1",
"project_id": "1",
"title": "...",
...
},
...
]
},
...
},
...
]
},
"total_items": 2
}
Since I've not found an apigility conform solution for implementing lists with nested lists (in this case projects with a list of images for every project list item, see here). I have to deal with the Paginator and DbAdapter and provide the page parameter manually:
class ProjectResource extends AbstractResourceListener {
...
public function fetchAll($params = array()) {
$pageNumber = $this->getEvent()->getRouteMatch()->getParam('page', 1); <-- that doesn't work
$projectService = $this->getProjectService();
$offset = $pageNumber > 0 ? $pageNumber - 1 : 0;
$config = $this->getServiceManager()->get('Config');
$itemCountPerPage = $config['zf-rest']['Portfolio\\V2\\Rest\\Project\\Controller']['page_size'];
$projects = $projectService->getProjects($offset, $itemCountPerPage);
return $projects;
}
...
}
The problem is, that $this->getEvent()->getRouteMatch()->getParam('page', 1) doesn't work. Instead of the page parameter, $this->getEvent()->getRouteMatch()->getParams() returns
Array
(
[controller] => Portfolio\V2\Rest\Project\Controller
[version] => 2
)
How to access request parameters?
Request parameters have first to be added onto the whitelist. It can be done over the Apigility GUI or directly in the config:
module.config.php
return array(
...
'zf-rest' => array(
...
'Portfolio\\V2\\Rest\\Project\\Controller' => array(
...
'collection_query_whitelist' => array('page'),
...
),
...
),
);
Then the parameter can be accessed over the arguments of the end point methods of the Resource class:
public function fetchAll($params = array()) {
$projectService = $this->getProjectService();
$config = $this->getServiceManager()->get('Config');
$itemCountPerPage = $config['zf-rest']['Portfolio\\V2\\Rest\\Project\\Controller']['page_size'];
$pageNumber = isset($params['page']) && intval($params['page']) > 0
? $params['page']
: 1
;
$offset = ($pageNumber - 1) * $itemCountPerPage;
$projects = $projectService->getProjects($offset, $itemCountPerPage);
return $projects;
}
See also the Apiglity documentation: ZF REST -> Configuration -> User Configuration -> collection_query_whitelist.
Having a Term that may consist of anything such as orddicts, lists of orddicts, orddicts of orddicts, list of lists, proplists of orddicts or ... such as:
Term1 = [
{"AAA", [
{ "K1", "ka1" },
{ "K2", "ka2" },
{ "K3", "ka3" }
]
},
{"BBB","one"},
{"CCC", [
{ "K1", "kb1" },
{ "K2", "" },
{ "K3", "kb3" }
]
},
{"DDD", [
[
{ "K1", "kc1" },
{ "K2", "kc2" }
],
[
{ "K1", "kd1" },
{ "K2", "kd2" }
],
"CACETA",
123
]
},
{"EEE", [
{ "K1", "kb1" },
{ "K2", 1122 },
{ "K3", "kb3" }
]
},
{ "T1", "T2", "T3" },
123,
{ "X" },
[ 1, 2, 3, { "K5", "V5" } ]
],
I would need to produce a list of all proplists [{K,V},...] such as
[
{ "AAA" , [ ...... ] },
{ "K1" , "ka1" },
{ "K2" , "ka2" },
...
{ "BBB" ,"one"},
{ "CCC" , [ ... ] },
{ "K1" , "kb1" },
...
{ "K5", "V5" }
]
notice that there are keys that must repeat along the list, their value may be a string, a list, a tupple or number, anything.
the last items in the data in the example above, such as { "T1", "T2", "T3" } should not be in the result since it is not a proplist of two terms { K, V}, but the nested { "K5", "V5" } is and should be part of the result.
I looked at this similar solution and tried to tune it up a little bit, but it is getting hard for my novice erlang brain to get it to work with my scenario above.
Here is an example of what I am trying to use to make it work, but there are some errors, pattern matching related:
extractPropList( [], ResultList ) -> ResultList;
extractPropList( [H|T], ResultList ) -> extractPropList(T, extractPropList(H, ResultList));
extractPropList( {K,V}, ResultList ) -> [ {K,V} | extractPropList(K, extractPropList(V, ResultList)) ].
While testing the above approach, the missing part was the last row that treats a term that had no other matching ( not a list, not a {K,V} ):
extractPropLists( [], ResultList ) -> ResultList;
extractPropLists( [H|T], ResultList ) -> extractPropLists(T, extractPropLists(H, ResultList));
extractPropLists( {K,V}, ResultList ) -> [ {K,V} | extractPropLists(K, extractPropLists(V, ResultList)) ];
extractPropLists( T, ResultList ) -> ResultList.
Given data similar to the avove, the results I obtained where
[{"EEE",[{"K1","kb1"},{"K2",1122},{"K3","kb3"}]},
{"K3","kb3"},
{"K2",1122},
{"K1","kb1"},
{"DDD",
[[{"K1","kc1"},{"K2","kc2"}],
[{"K1","kd1"},{"K2","kd2"}],
"CACETA",123]},
{"K2","kd2"},
{"K1","kd1"},
{"K2","kc2"},
{"K1","kc1"},
{"CCC",[{"K1","kb1"},{"K2","kb2"},{"K3","kb3"}]},
{"K3","kb3"},
{"K2","kb2"},
{"K1","kb1"},
{"BBB","one"},
{"AAA",[{"K1","ka1"},{"K2","ka2"},{"K3","ka3"}]},
{"K3","ka3"},
{"K2","ka2"},
{"K1","ka1"}]